package com.erp.service;

import com.erp.common.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class FavoritesService extends BaseService {

    public List<Map<String, Object>> getFavoriteMenuList(Map<String, Object> params) {
        return sqlSession.selectList("favorites.selectFavoriteMenuList", params);
    }

    @Transactional
    public Map<String, Object> insertFavorite(Map<String, Object> params) {
        sqlSession.insert("favorites.insertFavorite", params);
        Map<String, Object> result = new HashMap<>();
        result.put("user_id", params.get("user_id"));
        result.put("menu_objid", params.get("menu_objid"));
        return result;
    }

    @Transactional
    public int deleteFavorite(Map<String, Object> params) {
        return sqlSession.delete("favorites.deleteFavorite", params);
    }

    public boolean exists(Map<String, Object> params) {
        Integer cnt = sqlSession.selectOne("favorites.selectFavoriteExists", params);
        return cnt != null && cnt > 0;
    }
}
