package org.qinan.safetyeval.adapter.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.qinan.safetyeval.client.api.AccountApi;
import org.qinan.safetyeval.client.co.AccountCO;
import org.qinan.safetyeval.client.dto.*;
import org.qinan.safetyeval.infrastructure.dataobject.base.Req;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户适配层（Controller）
 *
 * @author safety-eval
 */
@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/safetyEval/account")
public class AccountController {

    @Resource
    private AccountApi accountApi;

    @ApiOperation("新增用户")
    @PostMapping("/save")
    public SingleResponse<AccountCO> add(@Validated @RequestBody AccountAddCmd cmd) {
        return accountApi.add(cmd);
    }

    @ApiOperation("查询用户详情")
    @GetMapping("/get")
    public SingleResponse<AccountCO> get(@ApiParam("主键ID") @RequestParam Long id) {
        return accountApi.get(id);
    }

    @ApiOperation("修改用户")
    @PostMapping("/modify")
    public SingleResponse<AccountCO> modify(@Validated @RequestBody AccountModifyCmd cmd) {
        return accountApi.modify(cmd);
    }

    @ApiOperation("删除用户")
    @PostMapping("/delete")
    public SingleResponse<Void> delete(@ApiParam("主键ID") @RequestBody Req<Long> req) {
        return accountApi.delete(req.getData());
    }

    @ApiOperation("分页查询用户")
    @GetMapping("/page")
    public PageResponse<AccountCO> page(@Validated AccountPageQuery query) {
        return accountApi.page(query);
    }

    @ApiOperation("用户同步gbs")
    @GetMapping("/syncUserToGBS")
    public SingleResponse<AccountCO> syncUserToGBS(@ApiParam("账号") @RequestParam String account) {
        return accountApi.syncUserToGBS(account);
    }

    @ApiOperation("验证码校验")
    @GetMapping("/verificationCode")
    public SingleResponse<AccountCO> verificationCode(@ApiParam("手机号") @RequestParam String phone, @ApiParam("验证码") @RequestParam String code) {
        return accountApi.verificationCode(phone, code);
    }

    @ApiOperation("校验用户是监管或机构: 1-机构端,2监管端")
    @GetMapping("/checkTerminalType")
    public SingleResponse<Integer> checkTerminalType() {
        return accountApi.checkTerminalType();
    }

}
