package com.dbnt.kcscbackend.commonCode.repository;

import com.dbnt.kcscbackend.commonCode.entity.TnResearch;
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.Map;


public interface TnResearchRepository extends JpaRepository<TnResearch, Long> {

    @Query(value = "CALL sp_add_tn_research (" +
            ":_rs_title, " +
            "TO_TIMESTAMP(" +
            "    :_rs_start_date," +
            "    'YYYYMMDDHH24MISS'" +
            ")::::timestamptz AT TIME ZONE 'UTC', " +
            "TO_TIMESTAMP(" +
            "    :_rs_end_date," +
            "    'YYYYMMDDHH24MISS'" +
            ")::::timestamptz AT TIME ZONE 'UTC', " +
            ":_rs_director, " +
            ":_rs_purpose, " +
            ":_rs_contents, " +
            ":_rs_effect, " +
            ":_modi_id, " +
            ":_result_count, " +
            ":_result_code, " +
            ":_error_message)",
            nativeQuery = true)
    Map<String, Object> spAddTnResearch(
            @Param("_rs_title")             String          rsTitle,
            @Param("_rs_start_date")        String          rsStartDate,
            @Param("_rs_end_date")          String          rsEndDate,
            @Param("_rs_director")          String          rsDirector,
            @Param("_rs_purpose")           String          rsPurpose,
            @Param("_rs_contents")          String          rsContents,
            @Param("_rs_effect")            String          rsEffect,
            @Param("_modi_id")              String          modiId,
            @Param("_result_count")         Integer         resultCount,
            @Param("_result_code")          String          resultCode,
            @Param("_error_message")        String          errorMessage
    );


    @Query(value = "CALL sp_update_tn_research (" +
            ":_rs_seq, " +
            "TO_TIMESTAMP(" +
            "    :_rs_start_date," +
            "    'YYYYMMDDHH24MISS'" +
            ")::::timestamptz AT TIME ZONE 'UTC', " +
            "TO_TIMESTAMP(" +
            "    :_rs_end_date," +
            "    'YYYYMMDDHH24MISS'" +
            ")::::timestamptz AT TIME ZONE 'UTC', " +
            ":_rs_director, " +
            ":_rs_purpose, " +
            ":_rs_contents, " +
            ":_rs_effect, " +
            ":_modi_id, " +
            ":_result_count, " +
            ":_result_code, " +
            ":_error_message)",
            nativeQuery = true)
    Map<String, Object> spUpdateTnResearch(
            @Param("_rs_seq")               Integer         rsSeq,
            @Param("_rs_start_date")        String          rsStartDate,
            @Param("_rs_end_date")          String          rsEndDate,
            @Param("_rs_director")          String          rsDirector,
            @Param("_rs_purpose")           String          rsPurpose,
            @Param("_rs_contents")          String          rsContents,
            @Param("_rs_effect")            String          rsEffect,
            @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_research (" +
            ":_rs_seq, " +
            ":_modi_id, " +
            ":_result_count, " +
            ":_result_code, " +
            ":_error_message)",
            nativeQuery = true)
    Map<String, Object> spDeleteTnResearch(
            @Param("_rs_seq")           Integer       rsSeq,
            @Param("_modi_id")          String        modiId,
            @Param("_result_count")     Integer       resultCount,
            @Param("_result_code")      String        resultCode,
            @Param("_error_message")    String        errorMessage
    );



    TnResearch findByRsSeq(Long rsSeq);


}
