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

import com.its.op.dto.its.oper.UserGropMenuInf;
import com.its.op.entity.its.oper.TbUserInfr;
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 TbUserInfrRepository extends JpaRepository<TbUserInfr, String>, JpaSpecificationExecutor<TbUserInfr> {

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

    @Modifying
    @Query("UPDATE TbUserInfr m set m.pwd = :pswd where m.userId = :userId")
    void changePwd(@Param("pswd") String pswd, @Param("userId")String userId);

    @Query("select p.menuId as menuId from TbUserGropMenuAthr p " +
           " where p.athrYn = 'N' " +
           "   and p.gropId = (select m.gropId from TbUserInfr m " +
           "                    where m.userId = :userId)")
    List<UserGropMenuInf> findByIdMenuAthr(@Param("userId") String userId);
}
