package com.css.txw.mhzc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.css.ggzc.framework.common.pojo.CommonResult;
import com.css.txw.mhzc.pojo.HtYhxxbDTO;
import com.css.txw.mhzc.pojo.YhxxReqDTO;
import com.css.txw.mhzc.pojo.YhxxbDTO;
import com.css.txw.mhzc.pojo.vo.*;
import com.css.txw.mhzc.service.TxwMhzcHtyhxxbService;
import com.css.txw.mhzc.service.TxwMhzcYhxxbService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Tag(name = "用户信息接口")
@RestController
@RequestMapping("/user")
@Validated
@Slf4j
public class UserController {

    @Resource
    private TxwMhzcYhxxbService yhxxbService;

    @Resource
    private TxwMhzcHtyhxxbService htyhxxbService;

    @PostMapping("/initSessionByYhuuid")
    @Operation(summary = "初始化会话信息",description = "登录后提供用户初始化会话信息")
    public CommonResult<YhxxbDTO> initSessionByYhuuid(@RequestBody YhxxReqDTO reqDTO){
        return CommonResult.success(yhxxbService.initSessionByYhuuid(reqDTO));
    }
    @PostMapping("/initSessionByDid")
    @Operation(summary = "初始化会话信息",description = "根据did提供用户初始化会话信息")
    public CommonResult<YhxxbDTO> initSessionByDid(@RequestBody YhxxReqDTO reqDTO){
        return CommonResult.success(yhxxbService.initSessionByDid(reqDTO));
    }
    
    @PostMapping("/initSessionBySfzjhm")
    @Operation(summary = "初始化会话信息",description = "根据身份证号提供用户初始化会话信息")
    public CommonResult<YhxxbDTO> initSessionBySfzjhm(@RequestBody YhxxReqDTO reqDTO){
        return CommonResult.success(yhxxbService.initSessionBySfzjhm(reqDTO));
    }
    @PostMapping("/initSessionByDlzh")
    @Operation(summary = "初始化会话信息",description = "登录后提供用户初始化会话信息")
    public CommonResult<YhxxbDTO> initSessionByDlzh(@RequestBody YhxxReqDTO reqDTO){
        return CommonResult.success(yhxxbService.initSessionByDlzh(reqDTO));
    }

    @PostMapping("/register")
    @Operation(summary = "注册",description = "注册")
    public CommonResult<String> register(@RequestBody UserRegisterReqVO reqVO){
        return CommonResult.success(yhxxbService.register(reqVO));
    }

    
    @PostMapping("/saveYhxxByDid")
    @Operation(summary = "保存did用户信息",description = "保存did用户信息")
    public CommonResult<YhxxbDTO> saveYhxxByDid(@RequestBody YhxxbDTO yhxx){
        return CommonResult.success(yhxxbService.saveYhxxByDid(yhxx));
    }
    
    @PostMapping("/updateDid")
    @Operation(summary = "更新用户did信息",description = "更新用户did信息")
    public CommonResult<YhxxbDTO> updateDid(@RequestBody YhxxbDTO yhxx){
        return CommonResult.success(yhxxbService.updateDid(yhxx));
    }
    
    @PostMapping("/initHtSessionByDlzh")
    @Operation(summary = "初始化用户信息")
    CommonResult<HtYhxxbDTO> initHtSessionByDlzh(@RequestBody YhxxReqDTO reqDTO){
        return CommonResult.success(htyhxxbService.initHtSessionByDlzh(reqDTO));
    }

    @PostMapping("/initHtSessionByYhuuid")
    @Operation(summary = "初始化用户信息")
    CommonResult<HtYhxxbDTO> initHtSessionByYhuuid(@RequestBody YhxxReqDTO reqDTO){
        return CommonResult.success(htyhxxbService.initHtSessionByYhuuid(reqDTO));
    }

    @PostMapping("/lockUser")
    @Operation(summary = "锁定用户")
    public CommonResult<Integer> lockUser(@RequestBody UserLockVO lockVO){
        return CommonResult.success(yhxxbService.lockUser(lockVO));
    }

    @PostMapping("/unlockUser")
    @Operation(summary = "解锁用户")
    public CommonResult<Integer> unlockUser(@RequestBody UserLockVO infoVO){
        return CommonResult.success(yhxxbService.unlockUser(infoVO));
    }

    @PostMapping("/init")
    @Operation(summary = "初始化用户信息")
    CommonResult<SessionVO> init(){
        return CommonResult.success(yhxxbService.init());
    }

    @PostMapping("/getAllUser")
    @Operation(summary = "用户列表")
    CommonResult<Page<UserVO>> getAllUser(@RequestBody UserReqVO reqVO){
        return CommonResult.success(yhxxbService.getAllUser(reqVO));
    }

    @PostMapping("/getAllUserId")
    @Operation(summary = "用户列表")
    CommonResult<List<String>> getAllUserId(){
        return CommonResult.success(yhxxbService.getAllUserId());
    }

    @GetMapping("/resetPassword")
    @Operation(summary = "用户列表")
    CommonResult<String> resetPassword(@RequestParam("yhUuid") String yhuuid){
        return CommonResult.success(yhxxbService.resetPassword(yhuuid));
    }

}
