package com.ruoyi.web.controller.app;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.AliLoginBody;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.domain.model.WxLoginBody;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.service.SysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 前台用户身份认证Controller
 * @author 辉
 * 2024/3/6
 */
@Api(tags = "前台用户身份认证")
@RestController
@RequestMapping("/app/auth")
public class AppAuthController extends BaseController {

    @Autowired
    private SysLoginService loginService;

    @Deprecated
    @ApiOperation("前台用户账号密码登录")
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody body) {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.appLogin(body.getUsername(), body.getPassword());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    /**
     * 前台用户微信登录
     * @return token
     */
    @Log(title = "微信授权登录", businessType = BusinessType.OTHER)
    @ApiOperation("微信授权登录")
    @PostMapping("/wxLogin")
    public AjaxResult wxLogin(@RequestBody @Validated WxLoginBody body)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.wxLogin(body);
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    /**
     * 前台用户支付宝登录
     * @return token
     */
    @Log(title = "支付宝授权登录", businessType = BusinessType.OTHER)
    @ApiOperation("支付宝授权登录")
    @PostMapping("/aliLogin")
    public AjaxResult aliLogin(@RequestBody @Validated AliLoginBody body)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.aliLogin(body);
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }


}
