package com.its.op.security;

import com.its.op.dao.repository.its.oper.TbUserCnncHsRepository;
import com.its.op.dao.repository.its.oper.TbUserInfrRepository;
import com.its.op.entity.its.oper.TbUserInfr;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Slf4j
@Service
@RequiredArgsConstructor
public class WebLoginService implements UserDetailsService {

    private final TbUserInfrRepository userRepo;
    private final TbUserCnncHsRepository cnncHsRepo;

    @Override
    public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
        //log.info("loadUserByUsername: {}", userId);
        Optional<TbUserInfr> optUserInfr = this.userRepo.findById(userId);
        if (optUserInfr.isPresent()) {
            return optUserInfr.get().toVo();
        }
        else {
            throw new UsernameNotFoundException(userId + " 을(를) 찾을 수 없습니다.");
        }
//        TbUserInfr userInfr = optUserInfr.orElseThrow(() -> new UsernameNotFoundException(userId + " 을(를) 찾을 수 없습니다."));
//        return userInfr.toVo();
    }
}
