package incheon.ags.mrb.share.mapper;

import org.apache.ibatis.annotations.Param;

import incheon.ags.mrb.share.vo.RecipeShrnDtlVO;

import java.util.List;

/**
 * 레시피 공유 대상 상세 매퍼 인터페이스
 * - 레시피 공유 대상자 관리
 */
@org.egovframe.rte.psl.dataaccess.mapper.Mapper @incheon.com.config.annotation.MainDB public interface RecipeShrnDtlMapper {

    /**
     * 공유 ID별 공유 대상 목록 조회
     * @param shrnId 공유 ID
     * @return 공유 대상 목록
     * @throws Exception
     */
    List<RecipeShrnDtlVO> selectRecipeShrnDtlListByShrnId(Integer shrnId);

    /**
     * 레시피 ID별 공유 대상 목록 조회
     * @param recipeId 레시피 ID
     * @return 공유 대상 목록
     * @throws Exception
     */
    List<RecipeShrnDtlVO> selectRecipeShrnDtlListByRecipeId(Integer recipeId);

    /**
     * 가져오기 여부별 목록 조회
     * @param shrnId 공유 ID
     * @param mporEn 가져오기 여부 (N:미가져옴, Y:가져옴)
     * @return 공유 대상 목록
     * @throws Exception
     */
    List<RecipeShrnDtlVO> selectRecipeShrnDtlListByType(@Param("shrnId") Integer shrnId,
                                                          @Param("mporEn") String mporEn);

    /**
     * 특정 사용자에게 공유된 레시피 목록 조회
     * @param shrnTrgtId 사용자 ID
     * @return 공유된 레시피의 공유 정보 목록
     * @throws Exception
     */
    List<RecipeShrnDtlVO> selectSharedRecipesByTarget(@Param("shrnTrgtId") String shrnTrgtId);

    /**
     * 레시피 공유 대상 등록
     * @param recipeShrnDtlVO 레시피 공유 대상 정보
     * @throws Exception
     */
    void insertRecipeShrnDtl(RecipeShrnDtlVO recipeShrnDtlVO);

    /**
     * 레시피 공유 대상 일괄 등록
     * @param recipeShrnDtlList 레시피 공유 대상 목록
     * @throws Exception
     */
    void insertRecipeShrnDtlList(List<RecipeShrnDtlVO> recipeShrnDtlList);

    /**
     * 레시피 공유 대상 삭제
     * @param shrnId 공유 ID
     * @param mporEn 가져오기 여부
     * @param shrnTrgtId 공유 대상 ID
     * @throws Exception
     */
    void deleteRecipeShrnDtl(@Param("shrnId") Integer shrnId,
                               @Param("mporEn") String mporEn,
                               @Param("shrnTrgtId") String shrnTrgtId);

    /**
     * 공유 ID별 공유 대상 전체 삭제
     * @param shrnId 공유 ID
     * @throws Exception
     */
    void deleteRecipeShrnDtlByShrnId(Integer shrnId);

    /**
     * 레시피 ID별 공유 대상 전체 삭제 (레시피 삭제 시)
     * @param recipeId 레시피 ID
     * @throws Exception
     */
    void deleteRecipeShrnDtlByRecipeId(Integer recipeId);

    /**
     * 공유 대상 중복 확인
     * @param recipeShrnDtlVO 레시피 공유 대상 정보
     * @return 중복 개수
     * @throws Exception
     */
    int checkRecipeShrnDtlExists(RecipeShrnDtlVO recipeShrnDtlVO);

    /**
     * 공유 대상 개수 조회
     * @param shrnId 공유 ID
     * @return 공유 대상 개수
     * @throws Exception
     */
    int countRecipeShrnDtlByShrnId(Integer shrnId);

    /**
     * 가져오기 여부 업데이트
     * @param recipeId 레시피 ID
     * @param shrnTrgtId 공유 대상 ID
     * @param mporEn 가져오기 여부 (N:미가져옴, Y:가져옴)
     * @throws Exception
     */
    void updateShrnTrgtCd(@Param("recipeId") Integer recipeId,
                      @Param("shrnTrgtId") String shrnTrgtId,
                      @Param("shrnTrgtCd") String shrnTrgtCd);
}
