package com.easyproject.client.controller.member;

import cn.hutool.core.util.ObjectUtil;
import com.easyproject.common.core.domain.AjaxClientResult;
import com.easyproject.common.core.domain.entity.ClientMember;
import com.easyproject.common.core.domain.model.LoginBody;
import com.easyproject.common.core.redis.RedisCache;
import com.easyproject.common.utils.SecurityMemberUtils;
import com.easyproject.core.web.service.MemberLoginService;
import com.easyproject.clientbus.service.member.IClientMemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>方法说明: 用户登录验证
 * <p>参数说明:
 * <p>返回说明:
 * <p>创建时间: 2025/2/11 0011 19:34
 * <p>创  建  人: JAVA —— java001
 **/
@Slf4j
@RestController
@RequestMapping("/member")
public class MemberLoginController {

    @Autowired
    private MemberLoginService loginService;
    @Resource
    private IClientMemberService clientMemberService;
    @Resource
    private RedisCache redisCache;

    /**
     * <p>方法说明: 账号登录方法
     * <p>参数说明:
     * <p>返回说明:
     * <p>创建时间: 2025/2/13 0013 14:35
     * <p>创  建  人: JAVA —— java001
     **/
    @PostMapping("/loginDeleteInfo")
    public AjaxClientResult login(@RequestBody LoginBody loginBody) {
        return loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid());
    }

    /**
     * <p>方法说明: 获取用户信息
     * <p>参数说明:
     * <p>返回说明:
     * <p>创建时间: 2025/2/13 0013 16:25
     * <p>创  建  人: JAVA —— java001
     **/
    @GetMapping("/getMemberInfoDeleteInfo")
    public AjaxClientResult getMemberInfo() {
        ClientMember member = SecurityMemberUtils.getLoginMember().getMember();
        if (ObjectUtil.isEmpty(member)) {
            return AjaxClientResult.error();
        }

        member = clientMemberService.selectMemberById(member.getId());

        return AjaxClientResult.success(member);
    }

}
