package com.kospo.talk.service.impl;

import com.kospo.talk.model.Favorite;
import com.kospo.talk.payload.FavoriteDto;
import com.kospo.talk.repository.FavoriteRepository;
import com.kospo.talk.service.FavoriteService;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class FavoriteServiceImpl implements FavoriteService {
    private final FavoriteRepository favoriteRepository;

    @Transactional
    @Override
    public List<FavoriteDto> findBySabun(String sabun) {
        return favoriteRepository.findByIdSabun(sabun).stream().map(FavoriteDto::to).toList();
    }

    @Override
    public void save(FavoriteDto favoriteDto) {
        favoriteRepository.save(Favorite.to(favoriteDto));
    }

    @Override
    public void delete(FavoriteDto favoriteDto) {
        favoriteRepository.delete(Favorite.to(favoriteDto));
    }
}
