package com.its.op.dao.repository.its.code;

import com.its.op.entity.its.code.TbCmmnCd;
import com.its.op.entity.its.code.TbCmmnCdKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TbCmmnCdRepository extends JpaRepository<TbCmmnCd, TbCmmnCdKey>, JpaSpecificationExecutor<TbCmmnCd> {

    @Query("select p from TbCmmnCd p")
    List<TbCmmnCd> findAll();

    @Query("select p from TbCmmnCd p where p.cmmnClsfCd = :cmmnClsfCd")
    List<TbCmmnCd> findAllByCmmnClsfCd(@Param("cmmnClsfCd") String cmmnClsfCd);

    @Query("select p from TbCmmnCd p where p.cmmnClsfCd = :cmmnClsfCd and  p.cmmnCd = :cmmnCd")
    TbCmmnCd findAllByCmmnClsfCdCmmnCd(@Param("cmmnClsfCd") String cmmnClsfCd, @Param("cmmnCd") String cmmnCd);

    @Transactional
    @Modifying // select 문이 아님을 나타낸다
    @Query("delete from TbCmmnCd p where p.cmmnClsfCd = :cmmnClsfCd")
    void deleteByClsfCd(@Param("cmmnClsfCd") String cmmnClsfCd);

}
