package com.auth.module.security.service.strategy;

import com.auth.dao.base.entity.UserEntity;
import com.auth.dao.base.mapper.v1.UserMapper;
import com.auth.model.base.dto.LoginDto;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

/**
 * 使用用户名登录
 */
public class DefaultLoginStrategy implements LoginStrategy {
    private final UserMapper userMapper;

    public DefaultLoginStrategy(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    /**
     * 登录鉴定方法
     * 默认登录方式，使用用户名查询用户
     *
     * @param loginDto 登录参数
     * @return 鉴定身份验证
     */
    @Override
    public UserEntity authenticate(LoginDto loginDto) {
        String username = loginDto.getUsername();

        // 查询用户相关内容
        LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserEntity::getUsername, username);
        return userMapper.selectOne(queryWrapper);
    }

    /**
     * 登录完成后的内容
     *
     * @param loginDto  登录参数
     * @param adminUser 用户
     */
    @Override
    public void authenticateAfter(LoginDto loginDto, UserEntity adminUser) {

    }

}