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

import com.its.op.entity.its.facility.TbFcltSubj;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TbFcltSubjRepository extends JpaRepository<TbFcltSubj, Long>, JpaSpecificationExecutor<TbFcltSubj> {

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

    @Query("select p from TbFcltSubj p where p.delYn = 'N'")
    List<TbFcltSubj> findAllList();

    @Query(value = "SELECT NVL(MAX(SUBJ_NMBR), 0) + 1 AS NEWID FROM TB_FCLT_SUBJ", nativeQuery = true)
    Long getNewNmbr();

    @Query(value = "SELECT NVL(MAX(SUBJ_ID), 0) + 1 AS NEWID FROM TB_FCLT_SUBJ where FCLT_TYPE = :fcltType", nativeQuery = true)
    Long getNewSubjId(@Param("fcltType") String fcltType);

    @Query("select p from TbFcltSubj p where p.fcltType = :fcltType")
    List<TbFcltSubj> findAllByFcltType(@Param("fcltType") String fcltType);

}
