package com.sqx.modules.artificer.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.app.service.UserService;
import com.sqx.modules.artificer.entity.Artificer;
import com.sqx.modules.artificer.entity.Certification;
import com.sqx.modules.artificer.service.ArtificerService;
import com.sqx.modules.artificer.service.RealNameService;
import com.sqx.modules.message.entity.MessageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/realname")
@Api(value = "管理端-技师实名认证", tags = {"管理端-技师实名认证"})
public class RealNameController {

    @Autowired
    private RealNameService realNameService;
    @Autowired
    private UserService userService;
    @Autowired
    private ArtificerService artificerService;

    @ApiOperation("查看实名认证列表")
    @GetMapping(value = "selectRealNameList")
    public Result selectRealNameList(Integer page, Integer limit, Integer status, String userName, String phone,Long classifyId){
        return realNameService.selectRealNameList(page, limit, status, userName, phone,classifyId);
    }

    @GetMapping("/selectRealNameCount")
    @ApiOperation("查询实名待审核总和")
    public Result selectRealNameCount(){
        return Result.success().put("data",realNameService.count(new QueryWrapper<Certification>().eq("status",0)));
    }

    @PostMapping("/deleteRealName")
    @ApiOperation("删除技师实名认证")
    public Result deleteRealName(Long id){
        Certification certification = realNameService.getById(id);
        realNameService.removeById(id);
        UserEntity userEntity = userService.selectUserById(certification.getUserId());
        userEntity.setIsAuthentication(0);
        userService.updateById(userEntity);
        Artificer artificer = artificerService.selectArtificerByUserId(certification.getUserId());
        if(artificer!=null){
            artificer.setStatus(2);
            artificerService.updateById(artificer);
        }
        return Result.success();
    }

    @PostMapping("/updateRealName")
    @ApiOperation("修改技师实名认证")
    public Result updateRealName(@RequestBody Certification certification){
        realNameService.updateById(certification);
        return Result.success();
    }

    @ApiOperation("按id查看实名认证信息")
    @GetMapping(value = "selectRealNameById")
    public Result selectRealNameById(Long userId){
        return realNameService.selectRealNameById(userId);
    }

    @ApiOperation("审核实名认证")
    @PostMapping(value = "auditRealName")
    public Result auditRealName(@RequestBody Certification certification){
        return realNameService.auditRealName(certification);
    }

    @ApiOperation("管理端审核退还保证金")
    @PostMapping(value = "auditRefund")
    public Result auditRefund(Long userId, Integer type){
        return realNameService.auditRefund(userId, type);
    }

    @ApiOperation("查询保证金退款列表")
    @GetMapping("/selectRefundCashDepositList")
    public Result selectRefundCashDepositList(Integer page,Integer limit,String userName,String phone){
        return realNameService.selectRefundCashDepositList(page, limit, userName, phone);
    }


}
