package com.zcloud.primeport.web.close;


import com.alibaba.cola.dto.*;
import com.alibaba.cola.exception.BizException;
import com.zcloud.primeport.api.ClosedAreaCarApplyServiceI;
import com.zcloud.primeport.dto.ClosedAreaCarApplyAddCmd;
import com.zcloud.primeport.dto.ClosedAreaCarApplyAuditCmd;
import com.zcloud.primeport.dto.ClosedAreaCarApplyPageQry;
import com.zcloud.primeport.dto.ClosedAreaCarApplyUpdateCmd;
import com.zcloud.primeport.dto.clientobject.ClosedAreaCarApplyCO;
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-20 10:07:13
 */
@Api(tags = "封闭区域-车辆")
@RequestMapping("/${application.gateway}/closedAreaCarApply")
@RestController
@AllArgsConstructor
public class ClosedAreaCarApplyController {
    private final ClosedAreaCarApplyServiceI closedAreaCarApplyService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<ClosedAreaCarApplyCO> add(@Validated @RequestBody ClosedAreaCarApplyAddCmd cmd) {
        return closedAreaCarApplyService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    // todo 完善申请人查询，审批人查询 数据权限
    public PageResponse<ClosedAreaCarApplyCO> page(@RequestBody ClosedAreaCarApplyPageQry qry) {
        return closedAreaCarApplyService.listPage(qry);
    }

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

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

    @ApiOperation("审批车辆申请")
    @PostMapping("/auditCarApply")
    public Response auditCarApply(@RequestBody ClosedAreaCarApplyAuditCmd auditCmd) {
        if (!(auditCmd.getAuditFlag().equals(2) || auditCmd.getAuditFlag().equals(3))) {
            throw new BizException("只能是通过或者不通过");
        }
        closedAreaCarApplyService.auditCarApply(auditCmd);
        return Response.buildSuccess();
    }
}

