package com.zcloud.primeport.web.close;


import com.alibaba.cola.dto.*;
import com.alibaba.cola.exception.BizException;
import com.zcloud.primeport.api.ClosedAreaPersonApplyServiceI;
import com.zcloud.primeport.dto.ClosedAreaPersonApplyAddCmd;
import com.zcloud.primeport.dto.ClosedAreaPersonApplyAuditCmd;
import com.zcloud.primeport.dto.ClosedAreaPersonApplyAuthCmd;
import com.zcloud.primeport.dto.ClosedAreaPersonApplyPageQry;
import com.zcloud.primeport.dto.clientobject.ClosedAreaPersonApplyCO;
import com.zcloud.primeport.dto.clientobject.ClosedAreaPersonApplyDeptCO;
import com.zcloud.primeport.dto.clientobject.UserCo;
import com.zcloud.primeport.persistence.dataobject.UserDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * web-adapter
 *
 * @Author dearLin
 * @Date 2026-03-19 13:59:16
 */
@Api(tags = "人员封闭区域申请审批")
@RequestMapping("/${application.gateway}/closedAreaPersonApply")
@RestController
@AllArgsConstructor
public class ClosedAreaPersonApplyController {
    private final ClosedAreaPersonApplyServiceI closedAreaPersonApplyService;

    @ApiOperation("查询分公司里的人授权范围")
    @GetMapping("/getAuthorizationPersonInfo/{id}")
    public SingleResponse<ClosedAreaPersonApplyCO> getAuthorizationPersonInfo(@PathVariable("id") Long id) {
        return closedAreaPersonApplyService.getAuthorizationPersonInfo(id);
    }

    @ApiOperation("给分公司里的人授权二级门禁")
    @PostMapping("/authorizationPerson")
    public Response authPerson(@RequestBody ClosedAreaPersonApplyAuthCmd cmd) {
        closedAreaPersonApplyService.authPerson(cmd);
        return Response.buildSuccess();
    }

    @ApiOperation("审批人员审批")
    @PostMapping("/auditPersonApply")
    public Response auditPersonApply(@RequestBody ClosedAreaPersonApplyAuditCmd auditCmd) {
        if (!(auditCmd.getAuditFlag().equals(2) || auditCmd.getAuditFlag().equals(3))) {
            throw new BizException("只能是通过或者不通过");
        }
        closedAreaPersonApplyService.auditPersonApply(auditCmd);
        return Response.buildSuccess();
    }

    @ApiOperation("获取本单位人员信息数据，用于随行人员，企业人员权限列表")
    @PostMapping("/getCorpUserList")
    public PageResponse<UserCo> getCorpUserList(@RequestBody ClosedAreaPersonApplyPageQry qry) {
        return closedAreaPersonApplyService.getCorpUserList(qry);
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<ClosedAreaPersonApplyCO> add(@Validated @RequestBody ClosedAreaPersonApplyAddCmd cmd) {
        return closedAreaPersonApplyService.add(cmd);
    }

    @ApiOperation("待审批-已审批|申请中-申请记录分页")
    // todo  需配置审批，申请的不同数据 权限
    @PostMapping("/pendingApprovalRecordList")
    public PageResponse<ClosedAreaPersonApplyCO> pendingApprovalRecordList(@RequestBody ClosedAreaPersonApplyPageQry qry) {
        return closedAreaPersonApplyService.listPage(qry);
    }

    @ApiOperation("申请记录部门分页")
    @GetMapping("/pendingApprovalDeptList")
    public MultiResponse<ClosedAreaPersonApplyDeptCO> pendingApprovalDeptList() {
        return closedAreaPersonApplyService.deptList();
    }

//    @ApiOperation("所有数据")
//    @GetMapping("/listAll")
//    public MultiResponse<ClosedAreaPersonApplyCO> listAll() {
//        return MultiResponse.of(new ArrayList<ClosedAreaPersonApplyCO>());
//    }

    @ApiOperation("详情")
    @GetMapping("/{id}")
    public SingleResponse<ClosedAreaPersonApplyCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(closedAreaPersonApplyService.queryById(id));
    }

//    @ApiOperation("删除")
//    @DeleteMapping("/{id}")
//    public Response remove(@PathVariable("id") Long id) {
//        closedAreaPersonApplyService.remove(id);
//        return SingleResponse.buildSuccess();
//    }
}

