package com.dbnt.kcscbackend.commonCode.repository;

import com.dbnt.kcscbackend.commonCode.entity.TnCmtEvent;
import com.dbnt.kcscbackend.commonCode.entity.TnPopupMng;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;

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


public interface TnPopupMngRepository extends JpaRepository<TnPopupMng, Long> {

    @Query(value = "CALL sp_add_tn_popup_mng (" +
            ":_popup_title, " +
            "TO_TIMESTAMP(" +
            "    :_popup_start_date," +
            "    'YYYYMMDDHH24MISS'" +
            ")::::timestamptz AT TIME ZONE 'UTC', " +
            "TO_TIMESTAMP(" +
            "    :_popup_end_date," +
            "    'YYYYMMDDHH24MISS'" +
            ")::::timestamptz AT TIME ZONE 'UTC', " +
            ":_file_grp_id, " +
            ":_popup_contents, " +
            ":_modi_id, " +
            ":_popup_seq, " +
            ":_result_count, " +
            ":_result_code, " +
            ":_error_message)",
            nativeQuery = true)
    Map<String, Object> spAddTnPopupMng(
            @Param("_popup_title")          String          popupTitle,
            @Param("_popup_start_date")     String          popupStartDate,
            @Param("_popup_end_date")       String          popupEndDate,
            @Param("_file_grp_id")          String          fileGrpId,
            @Param("_popup_contents")       String          popupContents,
            @Param("_modi_id")              String          modiId,
            @Param("_popup_seq")            Integer         popupSeq,
            @Param("_result_count")         Integer         resultCount,
            @Param("_result_code")          String          resultCode,
            @Param("_error_message")        String          errorMessage
    );


    @Query(value = "CALL sp_update_tn_popup_mng (" +
            ":_popup_seq, " +
            ":_popup_title, " +
            "TO_TIMESTAMP(" +
            "    :_popup_start_date," +
            "    'YYYYMMDDHH24MISS'" +
            ")::::timestamptz AT TIME ZONE 'UTC', " +
            "TO_TIMESTAMP(" +
            "    :_popup_end_date," +
            "    'YYYYMMDDHH24MISS'" +
            ")::::timestamptz AT TIME ZONE 'UTC', " +
            ":_file_grp_id, " +
            ":_popup_contents, " +
            ":_modi_id, " +
            ":_result_count, " +
            ":_result_code, " +
            ":_error_message)",
            nativeQuery = true)
    Map<String, Object> spUpdateTnPopupMng(
            @Param("_popup_seq")            Integer         popupSeq,
            @Param("_popup_title")          String          popupTitle,
            @Param("_popup_start_date")     String          popupStartDate,
            @Param("_popup_end_date")       String          popupEndDate,
            @Param("_file_grp_id")          String          fileGrpId,
            @Param("_popup_contents")       String          popupContents,
            @Param("_modi_id")              String          modiId,
            @Param("_result_count")         Integer         resultCount,
            @Param("_result_code")          String          resultCode,
            @Param("_error_message")        String          errorMessage
    );


    @Query(value = "CALL sp_delete_tn_popup_mng (" +
            ":_popup_seq, " +
            ":_modi_id, " +
            ":_result_count, " +
            ":_result_code, " +
            ":_error_message)",
            nativeQuery = true)
    Map<String, Object> spDeleteTnPopupMng(
            @Param("_popup_seq")        Integer       popupSeq,
            @Param("_modi_id")          String        modiId,
            @Param("_result_count")     Integer       resultCount,
            @Param("_result_code")      String        resultCode,
            @Param("_error_message")    String        errorMessage
    );


    @Procedure("sp_is_valid_tn_popup_mng_id")
    int spIsValidTnPopupMngId( Integer        popupSeq );

    TnPopupMng findByPopupSeq(Long popupSeq);


}
