package cn.wisenergy.web.admin.controller.app;

import cn.wisenergy.common.utils.exception.CustomException;
import cn.wisenergy.common.utils.exception.RESP_CODE_ENUM;
import cn.wisenergy.common.utils.exception.BASE_RESP_CODE_ENUM;
import cn.wisenergy.common.utils.exception.BaseCustomException;
import cn.wisenergy.common.utils.exception.Result;
import cn.wisenergy.model.app.WorkUser;
import cn.wisenergy.service.WorkUserService;
import cn.wisenergy.web.admin.controller.common.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.commons.lang.StringUtils;
/**
 * @Authotr:陈奇
 * @QQ1799796883
 */
@RestController
@Api(tags = "用户模块")
@Slf4j
public class WorkUserController extends BaseController {
    @Autowired
    private WorkUserService workUserService;

    @ApiOperation(value = "根据id获取用户信息", notes = "根据id获取用户信息", httpMethod = "GET")
    @ApiImplicitParam(name = "id", value = "用户id", dataType = "int", required = true)
    @GetMapping(value = "/getUserInfo")
    public Result<WorkUser> getUserInfo(Integer id) {
        log.info("UserController[]getUserInfo[]input.param.id" + id);
        if (null == id) {
            throw new CustomException(RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
        }
        WorkUser user = workUserService.getUserById(id);
        return getResult(user);
    }

    @ApiOperation(value = "用户登录", notes = "用户登录", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loginName", value = "登录名", dataType = "string", required = true),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "string", required = true),
            @ApiImplicitParam(name = "source", value = "登录来源：PC/WAP", dataType = "string", required = true)
    })
    @GetMapping(value = "login")
    public Result<WorkUser> login(String loginName, String password, String source) {
        log.info("WorkUserController[]login[]input.param" + loginName + password + source);
        if (StringUtils.isEmpty(loginName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(loginName)) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
        }
        WorkUser workUser = workUserService.login(loginName, password, source);
        return getResult(workUser);
    }
}
