package com.ruoyi.web.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.realName.domain.RealName;
import com.ruoyi.bst.realName.domain.dto.RealNameTowEleDTO;
import com.ruoyi.bst.realName.service.RealNameService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.ValidGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LogBizType;

import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping("/app/realName")
public class AppRealNameController extends BaseController {

    @Autowired
    private RealNameService realNameService;

    @ApiOperation("用户人脸实名认证")
    @PutMapping("/realName")
    @Log(title = "用户人脸实名认证", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.REAL_NAME)
    public AjaxResult realName(@RequestBody @Validated(ValidGroup.Create.class) RealName realName){
        realName.setUserId(getUserId());
        return success(realNameService.faceRealName(realName));
    }

    @ApiOperation("用户二要素实名认证")
    @PutMapping("/twoElementRealName")
    @Log(title = "用户二要素实名认证", businessType = BusinessType.OTHER, bizIdName = "arg0", bizType = LogBizType.REAL_NAME)
    public AjaxResult twoElementRealName(@RequestBody @Validated(ValidGroup.Create.class) RealNameTowEleDTO dto){
        dto.setUserId(getUserId());
        return toAjax(realNameService.twoElementRealName(dto));
    }

    @ApiOperation("刷新用户实名认证结果")
    @GetMapping("/refreshRealName")
    @Log(title = "刷新用户实名认证结果", businessType = BusinessType.OTHER)
    public AjaxResult refreshRealName() {
        return AjaxResult.success("操作成功", realNameService.refreshRealName(getUserId()));
    }

}
