package itn.let.lett.service.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import egovframework.rte.psl.dataaccess.EgovAbstractDAO;
import itn.let.lett.service.CateConfVO;
import itn.let.lett.service.HashConfVO;
import itn.let.lett.service.LetterVO;
import itn.let.sym.ccm.cde.service.CateCode;
import itn.let.uss.umt.service.UserDefaultVO;

@Repository("LetterDAO")
public class LetterDAO  extends EgovAbstractDAO {

	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectLetterMessageCategoryList() throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectLetterMessageCategoryList");
	}
	
	public int insertLetterMessages(LetterVO letterVO) throws Exception{
		
		// 결과 리턴을 위해서 insert 이지만 update로 써준다
		return (int) update("LetterDAO.insertLetterMessages", letterVO);
	}
	
	public List<?> selectLetterMessageList(UserDefaultVO userSearchVO) throws Exception{
		
		return list("LetterDAO.selectLetterMessageList", userSearchVO);
	}
	
	public void deleteLetterMessage(String checkedIdForDel) throws Exception{
		
		update("LetterDAO.deleteLetterMessage", checkedIdForDel);
	}
	
	// 문자 우선순위 랜덤 업데이트 All
	public void updateLetterPriorityAll() throws Exception{
		update("LetterDAO.updateLetterPriorityAll");
	}
	
	public LetterVO letterMessagesDetail(LetterVO letterVO) throws Exception{
		
		return (LetterVO) select("LetterDAO.letterMessagesDetail", letterVO);
	}
	
	public int updateLetterMessages(LetterVO letterVO) throws Exception{
		
		return update("LetterDAO.updateLetterMessages", letterVO);
	}
	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectCateCodeTwoDptWithList(CateCode cateCode) throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectCateCodeTwoDptWithList", cateCode);
	}
	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectCateCodeThrDptWithList(CateCode cateCode) throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectCateCodeThrDptWithList", cateCode);
	}
	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectPhotoCateCodeWithList(CateCode cateCode) throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectPhotoCateCodeWithList", cateCode);
	}
	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectCateConfWithList(String categoryType) throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectCateConfWithList", categoryType);
	}
	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectCateConfWithList4Main(String categoryType) throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectCateConfWithList4Main", categoryType);
	}
	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectCateConfTwoDepthWithList(String categoryType) throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectCateConfTwoDepthWithList", categoryType);
	}
	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectCateConfThreeDepthWithList(CateCode cateCode) throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectCateConfThreeDepthWithList", cateCode);
	}
	
	@SuppressWarnings("unchecked")
	public List<HashConfVO> selectHashTagWithList(String msgType) throws Exception{
		
		return (List<HashConfVO>) list("LetterDAO.selectHashTagWithList", msgType);
	}
	
	public int insertletterPhotosInfo(LetterVO letterVO) throws Exception{
		
		return (int) update("LetterDAO.insertletterPhotosInfo", letterVO);
	}
	
	public List<?> selectLetterPhotosList(UserDefaultVO userSearchVO) throws Exception{
		
		return list("LetterDAO.selectLetterPhotosList", userSearchVO);
	}
	
	@SuppressWarnings("unchecked")
	public List<CateCode> selectPhotoCateCodeListWithId(String cateCode) throws Exception{
		
		return (List<CateCode>) list("LetterDAO.selectPhotoCateCodeListWithId", cateCode);
	}
	
	public LetterVO selectPhotosDetail(LetterVO letterVO) throws Exception{
		
		return (LetterVO) select("LetterDAO.selectPhotosDetail", letterVO);
	}
	
	public LetterVO selectPhotoFileList(String attchFileId) throws Exception{
		
		return (LetterVO) select("LetterDAO.selectPhotoFileList", attchFileId);
	}
	
	public int updateLetterPhotosInfo(LetterVO letterVO) throws Exception{
		
		return update("LetterDAO.updateLetterPhotosInfo", letterVO);
	}
	
	// 문자 발송 카테고리 관리
	
	public int insertCategoryConf(CateConfVO cateConfVO) throws Exception{
		
		//카테고리 번호로 카테고리 이름 받아오기
		String categoryCode = cateConfVO.getCategoryCode();
		@SuppressWarnings("unchecked")
		List<CateCode> cateCodeList = (List<CateCode>) list("LetterDAO.selectPhotoCateCodeListWithId", categoryCode);
		
		//받아온 카테고리 리스트에서 맞는 이름 셋팅해주기
		for(CateCode categoryNm : cateCodeList) {
			
			if(categoryCode.equals(categoryNm.getCateNo())) {
				
				cateConfVO.setCategoryNm(categoryNm.getCateNm());
				
			}
			
		}
		
		// 문자 발송 카테고리 정보 입력하기
		return update("LetterDAO.insertCategoryConf", cateConfVO);
	}
	
	public List<?> selectCategoryConfList(UserDefaultVO userSearchVO) throws Exception{
		
		return list("LetterDAO.selectCategoryConfList", userSearchVO);
	}
	
	public CateConfVO categoryConfDetail(CateConfVO cateConfVO) throws Exception{
		
		return (CateConfVO) select("LetterDAO.categoryConfDetail", cateConfVO);
	}
	
	public void deleteCategoryConf(String checkedIdForDel) throws Exception{
		
		delete("LetterDAO.deleteCategoryConf", checkedIdForDel);
		
	}
	
	public int updateCategoryConf(CateConfVO cateConfVO) throws Exception{
		
		//카테고리 번호로 카테고리 이름 받아오기
		String categoryCode = cateConfVO.getCategoryCode();
		@SuppressWarnings("unchecked")
		List<CateCode> cateCodeList = (List<CateCode>) list("LetterDAO.selectPhotoCateCodeListWithId", categoryCode);
		
		//받아온 카테고리 리스트에서 맞는 이름 셋팅해주기
		for(CateCode categoryNm : cateCodeList) {
			
			if(categoryCode.equals(categoryNm.getCateNo())) {
				
				cateConfVO.setCategoryNm(categoryNm.getCateNm());
				
			}
			
		}
		
		return update("LetterDAO.updateCategoryConf", cateConfVO);
		
	}
	
	public int insertHashTagConf(HashConfVO hashConfVO) throws Exception{
		
		return update("LetterDAO.insertHashTagConf", hashConfVO);
	}
	
	public List<?> selectHashTagConfList(UserDefaultVO userSearchVO) throws Exception{
		
		return list("LetterDAO.selectHashTagConfList", userSearchVO);
	}
	
	public HashConfVO hashTagConfDetail(HashConfVO hashConfVO) throws Exception{
		
		return (HashConfVO) select("LetterDAO.hashTagConfDetail", hashConfVO);
	}
	
	public int updateHashTagConf(HashConfVO hashConfVO) throws Exception{
		
		return update("LetterDAO.updateHashTagConf", hashConfVO);
	}
	
	public void deleteHashTagConf(String checkedIdForDel) throws Exception{
		
		delete("LetterDAO.deleteHashTagConf", checkedIdForDel);
	}
	
	// 맞춤제작 그림문자 리스트 불러오기
	public List<?> selectLetterPhotosCustomList(UserDefaultVO userSearchVO) throws Exception{
	 
	 return list("LetterDAO.selectLetterPhotosCustomList", userSearchVO);
	}
	
	// 문자템플릿 사용 누계
	public int updateTemplateUseCount(String attachFileId) throws Exception {
		return update("LetterDAO.updateTemplateUseCount", attachFileId);
	}
	
	public int updateChkAfterPriorityPlus(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateChkAfterPriorityPlus", letterVO);
	}

	public int updateChkListPriority(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateChkListPriority", letterVO);
	}

	public int updateOrderByPriority(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateOrderByPriority", letterVO);
	}
	
	public int updateNullPriority(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateNullPriority", letterVO);
	}
	
	
	public int updateChkCateAfterSortPlus(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateChkCateAfterSortPlus", letterVO);
	}
	
	public int updateChkCateListSort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateChkCateListSort", letterVO);
	}
	
	public int updateCateOrderBySort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateCateOrderBySort", letterVO);
	}
	
	public int updateCateNullSort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateCateNullSort", letterVO);
	}
	
	
	public int updateChkTagAfterSortPlus(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateChkTagAfterSortPlus", letterVO);
	}
	
	public int updateChkTagListSort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateChkTagListSort", letterVO);
	}
	
	public int updateTagOrderBySort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateTagOrderBySort", letterVO);
	}
	
	public int updateTagNullSort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateTagNullSort", letterVO);
	}
	
	//검색어 욕설 및 금지 단어 검색
	public int selectSwearWordSearchCnt(String searchKeyWord) throws Exception{
		return (int) select("LetterDAO.selectSwearWordSearchCnt", searchKeyWord);
	}
	
	// 문자템플릿 조회 누계
	public int updateSmsTemplateViewCount(String letterId) throws Exception {
		return update("LetterDAO.updateSmsTemplateViewCount", letterId);
	}
	
	// 제목, 해쉬태그 일괄변경
	public int updateHashTagList(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateHashTagList", letterVO);
	}	
	
	// 메인태그 관리
	@SuppressWarnings("unchecked")
	public List<LetterVO> selectMainTagList(LetterVO letterVO) throws Exception{
		return (List<LetterVO>) list("LetterDAO.selectMainTagList", letterVO);
	}	

	// 메인태그 상세
	public LetterVO selectMainTagDetail(LetterVO letterVO) throws Exception{
		return (LetterVO) select("LetterDAO.selectMainTagDetail", letterVO);
	}

	// 메인태그 등록
	public void insertMainTag(LetterVO letterVO) throws Exception{
		insert("LetterDAO.insertMainTag", letterVO);
	}
	
	// 메인태그 수정
	public void updateMainTag(LetterVO letterVO) throws Exception{
		update("LetterDAO.updateMainTag", letterVO);
	}	
	
	@SuppressWarnings("unchecked")
	public List<LetterVO> selectMainTagWebList(LetterVO letterVO) throws Exception{
		return (List<LetterVO>) list("LetterDAO.selectMainTagWebList", letterVO);
	}	
	
	public LetterVO selectFrsKeyword(LetterVO letterVO) throws Exception{
		return (LetterVO) select("LetterDAO.selectFrsKeyword", letterVO);
	}	
	
	// 베스트태그(메인) 목록 조회
	@SuppressWarnings("unchecked")
	public List<LetterVO> selectMainMsgTagWebList(LetterVO letterVO) throws Exception{
		return (List<LetterVO>) list("LetterDAO.selectMainMsgTagWebList", letterVO);
	}	
	
	// 메인 베스트 태그 관리
	@SuppressWarnings("unchecked")
	public List<LetterVO> selectBastMsgTagList(LetterVO letterVO) throws Exception {
		return (List<LetterVO>) list("LetterDAO.selectBastMsgTagList", letterVO);
	}

	// 메인 베스트 태그 상세
	public LetterVO selectBastMsgTagInfo(LetterVO letterVO) throws Exception {
		return (LetterVO) select("LetterDAO.selectBastMsgTagInfo", letterVO);
	}

	// 메인 베스트 태그 등록
	public void insertBastMsgTag(LetterVO letterVO) throws Exception {
		insert("LetterDAO.insertBastMsgTag", letterVO);
	}

	// 메인 베스트 태그 수정
	public void updateBastMsgTag(LetterVO letterVO) throws Exception {
		update("LetterDAO.updateBastMsgTag", letterVO);
	}
	
	public int updateChkBastMsgTagAfterSortPlus(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateChkBastMsgTagAfterSortPlus", letterVO);
	}

	public int updateChkBastMsgTagListSort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateChkBastMsgTagListSort", letterVO);
	}

	public int updateBastMsgTagOrderBySort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateBastMsgTagOrderBySort", letterVO);
	}

	public int updateBastMsgTagNullSort(LetterVO letterVO) throws Exception {
		return update("LetterDAO.updateBastMsgTagNullSort", letterVO);
	}
}
