package com.zcloud.fire.check.web;


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 com.zcloud.fire.check.api.FireRegionServiceI;
import com.zcloud.fire.check.dto.*;
import com.zcloud.fire.check.dto.clientobject.FireRegionCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * web-adapter
 *
 * @Author zhaokai
 * @Date 2025-11-26 10:13:09
 */
@Api(tags = "消防区域表")
@RequestMapping("/${application.gateway}/fireRegion")
@RestController
@AllArgsConstructor
public class FireRegionController {
    private final FireRegionServiceI fireRegionService;

    @ApiOperation("消防区域新增")
    @PostMapping("/save")
    public SingleResponse<FireRegionCO> add(@Validated @RequestBody FireRegionAddCmd cmd) {
        return fireRegionService.add(cmd);
    }

    @ApiOperation("消防区域列表分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('xfqywh')")
    public PageResponse<FireRegionCO> page(@RequestBody FireRegionPageQry qry) {
        return fireRegionService.listPage(qry);
    }
    @ApiOperation("股份端消防区域列表分页")
    @PostMapping("/mainList")
    public PageResponse<FireRegionCO> mainList(@RequestBody FireRegionPageQry qry) {
        return fireRegionService.listPage(qry);
    }

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

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

    @ApiOperation("删除多个")
    @PostMapping("/remove/ids")
    public Response removeBatch(@Validated @RequestBody FireRegionRemoveCmd cmd) {
        fireRegionService.removeBatch(cmd.getIds());
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody FireRegionUpdateCmd fireRegionUpdateCmd) {
        fireRegionService.edit(fireRegionUpdateCmd);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("修改启用禁用")
    @PostMapping("/editStatus")
    public SingleResponse editStatus(@Validated @RequestBody FireRegionUpdateStatusCmd fireRegionUpdateStatusCmd) {
        fireRegionService.editStatus(fireRegionUpdateStatusCmd);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("批量修改负责部门")
    @PostMapping("/editAllDepartment")
    public SingleResponse editAllDepartment(@Validated @RequestBody FireRegionUpdateDepartmentCmd fireRegionUpdateDepartmentCmd) {
        fireRegionService.editAllDepartment(fireRegionUpdateDepartmentCmd);
        return SingleResponse.buildSuccess();
    }
    //获取所有消防区域
    @ApiOperation("获取所有消防区域")
    @GetMapping("/listAll")
    public MultiResponse<FireRegionCO> listAll(@RequestParam(value = "corpinfoId", required = false) Long corpinfoId) {
        return MultiResponse.of(fireRegionService.listAll(corpinfoId));
    }
}

