package org.xyzh.auth.strategy.impl;

import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;
import org.xyzh.auth.strategy.LoginStrategy;
import org.xyzh.common.core.domain.LoginParam;
import org.xyzh.common.dto.sys.TbSysUserDTO;
import org.xyzh.api.system.service.SysUserService;
import org.xyzh.api.system.vo.SysUserVO;

/**
 * @description    微信二维码登录策略（PC端扫码登录）
 * @filename    WechatLoginStrategy.java
 * @author    yslg
 * @copyright xyzh
 * @since 2025-12-05
 */
@Component
public class WechatLoginStrategy implements LoginStrategy {

    @Autowired
    private SysUserService userService;


    @Override
    public String getLoginType() {
        return "wechat_qrcode";
    }

    @Override
    public boolean validate(LoginParam loginParam) {
        return loginParam.getWechatId() != null && !loginParam.getWechatId().trim().isEmpty();
    }

    @Override
    public SysUserVO findUser(LoginParam loginParam) {
        SysUserVO filter = new SysUserVO();
        filter.setWechatId(loginParam.getWechatId());
        SysUserVO user = userService.getLoginUser(filter).getData();
        if(user == null) {
            return null;
        }
        return user;
    }

    @Override
    public boolean verifyCredential(String inputCredential, String storedCredential) {
        // 微信登录通常不需要密码验证，通过微信授权码验证
        // 这里可以添加微信授权验证逻辑
        return true;
    }
}
