package com.its.api.its.repository.oper;

import com.its.api.its.model.entity.oper.TbGropMenuAthr;
import com.its.api.its.model.entity.oper.TbGropMenuAthrKey;
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 java.util.List;

@Repository
public interface TbGropMenuAthrRepository extends JpaRepository<TbGropMenuAthr, TbGropMenuAthrKey>, JpaSpecificationExecutor<TbGropMenuAthr> {

    @Query(value = "select p from TbGropMenuAthr p inner join fetch p.operMenu inner join fetch p.userGrop")
    List<TbGropMenuAthr> findAll();

    @Modifying // select 문이 아님을 나타낸다
    @Query("delete from TbGropMenuAthr p where p.gropId = :gropId and p.operSystMenuId = :operSystMenuId")
    void deleteByOperSystMenuId(@Param("gropId") String gropId, @Param("operSystMenuId") String operSystMenuId);

    @Modifying // select 문이 아님을 나타낸다
    @Query(value = "insert into TB_GROP_MENU_ATHR(GROP_ID, OPERSYST_MENU_ID, ATHR_YN) values(:gropId, :menuId, :authrYn)", nativeQuery = true)
    void insertData(@Param("gropId") String gropId, @Param("menuId") String menuId, @Param("authrYn") String authrYn);

}
