package com.zcloud.primeport.web.close;


import com.zcloud.primeport.api.ClosedAreaServiceI;
import com.zcloud.primeport.dto.ClosedAreaAddCmd;
import com.zcloud.primeport.dto.ClosedAreaCountCmd;
import com.zcloud.primeport.dto.ClosedAreaPageQry;
import com.zcloud.primeport.dto.ClosedAreaUpdateCmd;
import com.zcloud.primeport.dto.clientobject.ClosedAreaCO;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
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 10:27:50
 */
@Api(tags = "封闭区域")
@RequestMapping("/${application.gateway}/closedArea")
@RestController
@AllArgsConstructor
public class ClosedAreaController {
    private final ClosedAreaServiceI closedAreaService;

    @ApiOperation("树级结构")
    @GetMapping("/listTree")
    public MultiResponse<ClosedAreaCO> listTree(ClosedAreaPageQry qry) {
        return closedAreaService.listTree(qry);
    }
    @ApiOperation("统计港区里所有的封闭区域数与管辖单位数")
    @GetMapping("/getCountByHgAuthArea")
    public MultiResponse<ClosedAreaCO> getCountByHgAuthArea() {
        return closedAreaService.getCountByHgAuthArea();
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<ClosedAreaCO> add(@Validated @RequestBody ClosedAreaAddCmd cmd) {
        return closedAreaService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<ClosedAreaCO> page(@RequestBody ClosedAreaPageQry qry) {
        return closedAreaService.listPage(qry);
    }

    @ApiOperation("跟据港区选择对应的封闭区域")
    @GetMapping("/listAllByhgAuthArea")
    public MultiResponse<ClosedAreaCO> listAllByhgAuthArea(@RequestParam("hgAuthArea") String hgAuthArea) {

        return closedAreaService.listAllByhgAuthArea(hgAuthArea);
    }

    @ApiOperation("跟据管辖单位查询封闭区域")
    @GetMapping("/listAllByJurisdictionalCorpId/{id}")
    public MultiResponse<ClosedAreaCO> listAllByJurisdictionalCorpId(@PathVariable("id") Long id) {
        if (id == null) {
            id = AuthContext.getTenantId();
        }
        return closedAreaService.listAllByJurisdictionalCorpId(id);
    }

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

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

    @ApiOperation("删除多个")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam Long[] ids) {
        closedAreaService.removeBatch(ids);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody ClosedAreaUpdateCmd closedAreaUpdateCmd) {
        closedAreaService.edit(closedAreaUpdateCmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("区域人员和车辆统计")
    @PostMapping("/count")
    public MultiResponse count(@RequestBody ClosedAreaCountCmd closedAreaCountCmd) {
        return closedAreaService.count(closedAreaCountCmd);
    }
}

