package com.ruoyi.xq.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.BeanConvertUtil;
import com.ruoyi.xq.domain.User;
import com.ruoyi.xq.domain.UserAuth;
import com.ruoyi.xq.dto.admin.user.UserAuthAdminVo;
import com.ruoyi.xq.dto.admin.userauth.UserAuthAdminInfoVo;
import com.ruoyi.xq.service.UserAuthService;
import com.ruoyi.xq.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 用户认证管理
 *
 * @author 77
 * @date 2024-03-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xq/userAuth")
public class UserAuthController extends BaseController {

    private final UserAuthService userAuthService;

    /**
     * 查询用户认证管理列表
     */
    @SaCheckPermission("xq:userAuth:list")
    @GetMapping("/list")
    public TableDataInfo<UserAuthAdminVo> list(UserAuthAdminVo bo, PageQuery pageQuery) {
        Page<UserAuthAdminVo> page = userAuthService.pageAdmin(pageQuery, bo);
        return TableDataInfo.build(page);
    }

    /**
     * 获取用户认证管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xq:userAuth:query")
    @GetMapping("/{id}")
    public R<UserAuthAdminInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        UserAuthAdminInfoVo vo = userAuthService.getAdminById(id);
        return R.ok(vo);
    }


    /**
     * 修改用户认证管理
     */
    @SaCheckPermission("xq:userAuth:edit")
    @Log(title = "用户认证管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserAuth bo) {
        userAuthService.updateUserAuth(bo);
        return R.ok();
    }

}
