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.ENateOperRegDecAddDTO;
import com.chinaweal.aiccs.aiccs.susnate.dto.ENateOperRegDecQueryDTO;
import com.chinaweal.aiccs.aiccs.susnate.dto.ENateOperRegDecUpdateDTO;
import com.chinaweal.aiccs.aiccs.susnate.dto.EntBaseWithNateOperRegDecQueryDTO;
import com.chinaweal.aiccs.aiccs.susnate.entity.ENateOperRegDec;
import com.chinaweal.aiccs.aiccs.susnate.service.IENateOperRegDecService;
import com.chinaweal.aiccs.aiccs.susnate.vo.EntBaseWithNateOperRegDecVO;
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;

/**
 *
 * @author zhouxy
 * @since 2025-12-29
 */
@Api(tags = "2.冒用他人身份取得公司登记处理决定表")
@ApiSort(2)
@RestController
@RequestMapping("/eNateOperRegDec")
public class ENateOperRegDecController extends BaseController {

    @Resource
    private IENateOperRegDecService iENateOperRegDecService;

    @ApiOperation(value = "0.新增冒用他人身份取得公司登记处理决定", position = 0)
    @PostMapping("/addNateOperRegDec")
    public RestResult<ENateOperRegDec> addNateOperRegDec(@Valid @RequestBody ENateOperRegDecAddDTO dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return RestResult.error(ResultCode.PARAM_IS_INVALID, bindingResult.getFieldError().getDefaultMessage());
        }
        ENateOperRegDec data = iENateOperRegDecService.addNateOperRegDec(dto);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "1.修改冒用他人身份取得公司登记处理决定", position = 1)
    @PostMapping("/updateNateOperRegDec")
    public RestResult<ENateOperRegDec> updateNateOperRegDec(@Valid @RequestBody ENateOperRegDecUpdateDTO dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return RestResult.error(ResultCode.PARAM_IS_INVALID, bindingResult.getFieldError().getDefaultMessage());
        }
        ENateOperRegDec data = iENateOperRegDecService.updateNateOperRegDec(dto);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "2.删除冒用他人身份取得公司登记处理决定（软删除）", position = 2)
    @PostMapping("/deleteNateOperRegDec/{personatresId}")
    public RestResult<Boolean> deleteNateOperRegDec(@ApiParam(value = "冒用身份处理ID", required = true) @PathVariable("personatresId") String personatresId) {
        boolean result = iENateOperRegDecService.deleteNateOperRegDec(personatresId);
        return RestResult.ok(result);
    }

    @ApiOperation(value = "3.通过id查询冒用他人身份取得公司登记处理决定表", position = 3)
    @GetMapping("/getById/{id}")
    public RestResult<ENateOperRegDec> getById(@ApiParam(value = "ID", required = true) @PathVariable("id") String id) {
        ENateOperRegDec data = iENateOperRegDecService.getById(id);
        return RestResult.ok(data);
    }

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

        IPage<EntBaseWithNateOperRegDecVO> data = iENateOperRegDecService.listEntBaseWithNateOperRegDec(new Page<>(query.getCurrent(), query.getSize()), queryDTO);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "5.分页查询冒用他人身份取得公司登记处理决定表", position = 5)
    @PostMapping("/listNateOperRegDec")
    public RestResult<IPage<ENateOperRegDec>> listNateOperRegDec(@RequestBody BaseQuery<ENateOperRegDecQueryDTO> query) {
        ENateOperRegDecQueryDTO queryDTO = query.getEntity(ENateOperRegDecQueryDTO.class);
        if (queryDTO == null) {
            queryDTO = new ENateOperRegDecQueryDTO();
        }

        IPage<ENateOperRegDec> data = iENateOperRegDecService.listNateOperRegDec(new Page<>(query.getCurrent(), query.getSize()), queryDTO);
        return RestResult.ok(data);
    }

}
