package com.eactive.httpmockserver.login.service.impl;

import com.eactive.httpmockserver.common.entity.EnabledStatus;
import com.eactive.httpmockserver.login.dto.LoginRequestDTO;
import com.eactive.httpmockserver.login.service.LoginService;
import com.eactive.httpmockserver.user.entity.User;
import com.eactive.httpmockserver.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * 로그인을 처리하는 비즈니스 구현 클래스
 *
 * @author
 * @version 1.0
 * @see
 * @since 2009.03.06
 */
@Service("loginService")
@Transactional
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserService userService;



    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void processIncorrectLogin(LoginRequestDTO loginRequestDTO) {

        User user = userService.findByUserId(loginRequestDTO.getId());
        user.setLockCnt(user.getLockCnt() + 1);
        if (user.getLockCnt() >= 5) {
            user.setLockAt(EnabledStatus.Y);
        }
        userService.updateUser(user);
    }

}
