package org.jeecg.modules.userCode.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.bean.LoginReq;
import org.jeecg.modules.postBean.ReqUserRole;
import org.jeecg.modules.userCode.service.AppletLoginService;
import org.jeecg.modules.utils.ValidateTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 服务化 system模块 对外接口请求类
 *
 * @author: jeecg-boot
 */
@Slf4j
@RestController
@RequestMapping("/user/")
@Api(tags = "登陆选择身份等接口")
public class UserController {

    @Resource
    private AppletLoginService appletLoginService;


    //小程序授权登录
    @ApiOperation(value = "小程序-登录接口", notes = "小程序-登录接口")
    @GetMapping("/login")
    public Result<?> login(LoginReq loginReq) {
        return appletLoginService.appletLogin(loginReq);
    }


    @ApiOperation(value = "选择身份")
    @RequestMapping(value = "/role", method = RequestMethod.POST)
    public Result<JSONObject> role(@RequestBody ReqUserRole reqUserRole, @RequestHeader("X-Access-Token") String token) {
        if (ValidateTool.isNull(reqUserRole)) {
            return Result.error("参数错误");
        }

        return appletLoginService.role(reqUserRole,token);
    }


}
