package com.zcloud.zcGbsServicer.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.zcGbsServicer.api.RescueTeamServiceI;
import com.zcloud.zcGbsServicer.dto.RescueTeamAddCmd;
import com.zcloud.zcGbsServicer.dto.RescueTeamNameCheckQry;
import com.zcloud.zcGbsServicer.dto.RescueTeamPageQry;
import com.zcloud.zcGbsServicer.dto.RescueTeamScreenQry;
import com.zcloud.zcGbsServicer.dto.RescueTeamUpdateCmd;
import com.zcloud.zcGbsServicer.dto.clientobject.RescueTeamCO;
import com.zcloud.zcGbsServicer.dto.clientobject.RescueTeamScreenCO;
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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * web-adapter
 * @Author makejava
 * @Date 2026-01-21 17:23:00
 */
@Api(tags = "消防救援队")
@RequestMapping("/${application.gateway}/rescueTeam")
@RestController
@AllArgsConstructor
public class RescueTeamController {
    private final RescueTeamServiceI rescueTeamService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<RescueTeamCO> add(@Validated @RequestBody RescueTeamAddCmd cmd) {
        SSOUser ssoUser = AuthContext.getCurrentUser();
        return rescueTeamService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('xfjyd')")
    public PageResponse<RescueTeamCO> page(@RequestBody RescueTeamPageQry qry) {
        return rescueTeamService.listPage(qry);
    }

    @ApiOperation("名称判重")
    @PostMapping("/checkName")
    public SingleResponse<Boolean> checkName(@Validated @RequestBody RescueTeamNameCheckQry qry) {
        return rescueTeamService.checkName(qry);
    }

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

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

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

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

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody RescueTeamUpdateCmd rescueTeamUpdateCmd) {
        rescueTeamService.edit(rescueTeamUpdateCmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("可视化大屏-消防救援队查询")
    @PostMapping("/screenList")
    public PageResponse<RescueTeamScreenCO> screenList(@RequestBody RescueTeamScreenQry qry) {
        return rescueTeamService.listScreen(qry);
    }
}
