package com.tsiwebserver.service.impl;

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 com.tsiwebserver.VO.UserVO;
import com.tsiwebserver.mapper.LoginMapper;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
@Slf4j
public class LoginServiceImpl implements UserDetailsService{
	private final LoginMapper loginMapper;

	public void loginFail(String username) throws UsernameNotFoundException {
		this.loginMapper.loginFail(username);
		int failCnt = this.loginMapper.findUserId(username).getFailCnt();
		if (failCnt > 4) {
			this.loginMapper.fullFail(username);
		}

	}

	public void initFailCnt(String username) throws UsernameNotFoundException {
		this.loginMapper.initFailCnt(username);
	}

	public UserVO loadUserByUsername(String username) throws UsernameNotFoundException {
		UserVO vo = this.loginMapper.findUserId(username);
		return vo;
	}
	
}
