package cn.iocoder.yudao.module.wechat.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.wechat.service.WechatService;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO;
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 微信登录控制层
 *
 */
@RestController
@RequestMapping("/userClient/weChat")
@Tag(name = "微信登录")
@Validated
public class WechatLoginController {
    @Autowired
    private WechatService wechatService;

    @Resource
    private AdminAuthService authService;

    /**
     * 微信获取openId
     * @author vinjor-M
     * @date 9:53 2024/8/2
     * @param code 请求参数
    **/
    @GetMapping("/wechatLogin")
    @Operation(summary = "微信获取openId")
    public CommonResult<?> createCompany(String code) {
        return wechatService.loginByOpenId(code);
    }

    @PostMapping("/login")
    @PermitAll
    @Operation(summary = "使用账号密码登录")
    public CommonResult<AuthLoginRespVO> login(@RequestBody @Valid AuthLoginReqVO reqVO) {
        return success(authService.login(reqVO));
    }
}
