package com.its.api.its.repository.vms;

import com.its.api.its.model.entity.vms.TbVmsCtlr;
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 TbVmsCtlrRepository extends JpaRepository<TbVmsCtlr, Long>, JpaSpecificationExecutor<TbVmsCtlr> {

    @Query("select p from TbVmsCtlr p inner join fetch p.usagType inner join fetch p.type left outer join fetch p.state")
    List<TbVmsCtlr> findAll();

    @Query("select p from TbVmsCtlr p inner join fetch p.usagType inner join fetch p.type left outer join fetch p.state where p.delYn = 'N'")
    List<TbVmsCtlr> findAllList();

    @Query("select count(p.vmsCtlrNmbr) as total from TbVmsCtlr p where p.delYn = 'N'")
    Integer findAllListCount();

    @Query("select p from TbVmsCtlr p inner join fetch p.usagType inner join fetch p.type left outer join fetch p.state where p.vmsCtlrNmbr in :vmsIds and p.delYn = 'N'")
    List<TbVmsCtlr> findAllListByIds(@Param("vmsIds") List<Long> vmsIds);

    @Query("select p from TbVmsCtlr p inner join fetch p.usagType inner join fetch p.type left outer join fetch p.state where p.vmsTypeCd = :vmsTypeCd and p.delYn = 'N'")
    List<TbVmsCtlr> findAllListByTypeCd(@Param("vmsTypeCd") String vmsTypeCd);

}
