package com.dbnt.kcscbackend.file.repository;

import com.dbnt.kcscbackend.file.entity.TnAttachFile;
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;
import java.util.Optional;

public interface TnAttachFileRepository extends JpaRepository<TnAttachFile, Integer> {

  Optional<List<TnAttachFile>> findByFileGrpId(String fileGrpId);

  @Procedure("make_file_grp_id")
  String makeFileGrpId( String        modiId );

  @Query(value = "CALL sp_add_tn_attach_file (" +
          ":_file_grp_id, " +
          ":_file_order, " +
          ":_file_old_name, " +
          ":_file_new_name, " +
          ":_file_path, " +
          ":_file_size, " +
          ":_file_ext, " +
          ":_ip_address, " +
          ":_modi_id, " +
          ":_result_count, " +
          ":_result_code, " +
          ":_error_message)",
          nativeQuery = true)
  Map<String, Object> spAddTnAttachFile(
          @Param("_file_grp_id")            String          _file_grp_id,
          @Param("_file_order")             Integer         _file_order,
          @Param("_file_old_name")          String          _file_old_name,
          @Param("_file_new_name")          String          _file_new_name,
          @Param("_file_path")              String          _file_path,
          @Param("_file_size")              Long            _file_size,
          @Param("_file_ext")               String          _file_ext,
          @Param("_ip_address")             String          _ip_address,
          @Param("_modi_id")                String          _modi_id,
          @Param("_result_count")           Integer         resultCount,
          @Param("_result_code")            String          resultCode,
          @Param("_error_message")          String          errorMessage
  );


}
