package com.chinaweal.aiccs.aiccs.susnate.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaweal.aiccs.aiccs.susnate.dto.EntBaseWithSusNateOperRegQueryDTO;
import com.chinaweal.aiccs.aiccs.susnate.dto.ESusNateOperRegAddDTO;
import com.chinaweal.aiccs.aiccs.susnate.dto.ESusNateOperRegDto;
import com.chinaweal.aiccs.aiccs.susnate.dto.ESusNateOperRegQueryDTO;
import com.chinaweal.aiccs.aiccs.susnate.dto.ESusNateOperRegUpdateDTO;
import com.chinaweal.aiccs.aiccs.susnate.entity.ESusNateOperReg;
import com.chinaweal.aiccs.aiccs.susnate.service.IESusNateOperRegService;
import com.chinaweal.aiccs.aiccs.susnate.vo.EntBaseWithSusNateOperRegVO;
import com.chinaweal.aiccs.aiccs.susnate.vo.ESusNateVo;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.youfool.framework.springboot.base.query.BaseQuery;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;

/**
 *
 * @author zhouxy
 * @since 2025-12-29
 */
@Api(tags = "1.涉嫌冒用他人身份取得登记信息表")
@ApiSort(1)
@RestController
@RequestMapping("/eSusNateOperReg")
public class ESusNateOperRegController extends BaseController {

    @Resource
    private IESusNateOperRegService iESusNateOperRegService;

    @ApiOperation(value = "0.（新）新增涉嫌冒用他人身份取得登记信息", position = 0)
    @PostMapping("/addSusNateOperReg")
    public RestResult<ESusNateOperReg> addSusNateOperReg(@Valid @RequestBody ESusNateOperRegAddDTO dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return RestResult.error(ResultCode.PARAM_IS_INVALID, bindingResult.getFieldError().getDefaultMessage());
        }
        ESusNateOperReg data = iESusNateOperRegService.addSusNateOperReg(dto);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "1.（新）修改涉嫌冒用他人身份取得登记信息", position = 1)
    @PostMapping("/updateSusNateOperReg")
    public RestResult<ESusNateOperReg> updateSusNateOperReg(@Valid @RequestBody ESusNateOperRegUpdateDTO dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return RestResult.error(ResultCode.PARAM_IS_INVALID, bindingResult.getFieldError().getDefaultMessage());
        }
        ESusNateOperReg data = iESusNateOperRegService.updateSusNateOperReg(dto);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "2.（新）删除涉嫌冒用他人身份取得登记信息（软删除）", position = 2)
    @PostMapping("/deleteSusNateOperReg/{personateId}")
    public RestResult<Boolean> deleteSusNateOperReg(@ApiParam(value = "冒用ID", required = true) @PathVariable("personateId") String personateId) {
        boolean result = iESusNateOperRegService.deleteSusNateOperReg(personateId);
        return RestResult.ok(result);
    }

    @ApiOperation(value = "3.（新）通过id查询涉嫌冒用他人身份取得登记信息表", position = 3)
    @GetMapping("/getById/{id}")
    public RestResult<ESusNateOperReg> getById(@ApiParam(value = "ID", required = true) @PathVariable("id") String id) {
        ESusNateOperReg data = iESusNateOperRegService.getById(id);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "4.（新）分页查询市场主体信息（包含是否有涉嫌冒用他人身份取得登记信息的判断）", position = 4)
    @PostMapping("/listEntBaseWithSusNateOperReg")
    public RestResult<IPage<EntBaseWithSusNateOperRegVO>> listEntBaseWithSusNateOperReg(@RequestBody BaseQuery<EntBaseWithSusNateOperRegQueryDTO> query) {
        EntBaseWithSusNateOperRegQueryDTO queryDTO = query.getEntity(EntBaseWithSusNateOperRegQueryDTO.class);
        if (queryDTO == null) {
            queryDTO = new EntBaseWithSusNateOperRegQueryDTO();
        }

        IPage<EntBaseWithSusNateOperRegVO> data = iESusNateOperRegService.listEntBaseWithSusNateOperReg(new Page<>(query.getCurrent(), query.getSize()), queryDTO);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "5.（新）分页查询涉嫌冒用他人身份取得登记信息表", position = 5)
    @PostMapping("/listSusNateOperReg")
    public RestResult<IPage<ESusNateOperReg>> listSusNateOperReg(@RequestBody BaseQuery<ESusNateOperRegQueryDTO> query) {
        ESusNateOperRegQueryDTO queryDTO = query.getEntity(ESusNateOperRegQueryDTO.class);
        if (queryDTO == null) {
            queryDTO = new ESusNateOperRegQueryDTO();
        }

        IPage<ESusNateOperReg> data = iESusNateOperRegService.listSusNateOperReg(new Page<>(query.getCurrent(), query.getSize()), queryDTO);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "6.新增涉嫌冒用他人身份取得登记信息表", position = 6)
    @PostMapping("/save")
    public RestResult<ESusNateOperReg> saveESusNateOperReg(@RequestBody @Valid ESusNateOperReg eSusNateOperReg, BindingResult bindingResult) {
        eSusNateOperReg = iESusNateOperRegService.saveESusNateOperReg(eSusNateOperReg);
        return RestResult.ok(eSusNateOperReg);
    }

    @ApiOperation(value = "7.删除涉嫌冒用他人身份取得登记信息表", position = 7)
    @PostMapping("/delete")
    public RestResult<String> removeESusNateOperReg(@RequestParam @ApiParam("id") Serializable id) {
        iESusNateOperRegService.removeById(id);
        return RestResult.ok();
    }

    @ApiOperation(value = "8.修改涉嫌冒用他人身份取得登记信息表", position = 8)
    @PostMapping("/update")
    public RestResult<String> updateESusNateOperReg(@RequestBody @Valid ESusNateOperReg eSusNateOperReg, BindingResult bindingResult) {
        iESusNateOperRegService.updateById(eSusNateOperReg);
        return RestResult.ok();
    }

    @ApiOperation(value = "9.查询涉嫌冒用他人身份取得登记信息表", position = 9)
    @GetMapping("/get")
    public RestResult<ESusNateOperReg> getESusNateOperReg(@RequestParam @ApiParam("id") Serializable id) {
        ESusNateOperReg eSusNateOperReg = iESusNateOperRegService.getById(id);
        return RestResult.ok(eSusNateOperReg);
    }

    @ApiOperation(value = "10.分页查询涉嫌冒用公告", position = 10)
    @PostMapping("/list")
    public RestResult<IPage<ESusNateVo>> listESusNateOperReg(@RequestBody BaseQuery<ESusNateOperRegDto> query) {
        IPage<ESusNateVo> data = iESusNateOperRegService.selectESusNateVoList(query);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "11.新增冒用信息", position = 11)
    @PostMapping("/eSusNateVoSave")
    public RestResult<?> eSusNateVoSave(@RequestBody ESusNateVo eSusNateVo){
        iESusNateOperRegService.eSusNateVoSave(eSusNateVo);
        return RestResult.ok();
    }

    @ApiOperation(value = "12.修改冒用信息", position = 12)
    @PostMapping("/eSusNateVoUpdate")
    public RestResult<?> eSusNateVoUpdate(@RequestBody ESusNateVo eSusNateVo){
        iESusNateOperRegService.eSusNateVoUpdate(eSusNateVo);
        return RestResult.ok();
    }

    @ApiOperation(value = "13.删除冒用信息", position = 13)
    @PostMapping("/eSusNateVoRemove")
    public RestResult<?> eSusNateVoRemove(@RequestBody ESusNateVo eSusNateVo){
        iESusNateOperRegService.eSusNateVoRemove(eSusNateVo);
        return RestResult.ok();
    }
}
