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.WaterSourceServiceI;
import com.zcloud.zcGbsServicer.dto.WaterSourceAddCmd;
import com.zcloud.zcGbsServicer.dto.WaterSourcePageQry;
import com.zcloud.zcGbsServicer.dto.WaterSourceScreenQry;
import com.zcloud.zcGbsServicer.dto.WaterSourceUpdateCmd;
import com.zcloud.zcGbsServicer.dto.clientobject.WaterSourceCO;
import com.zcloud.zcGbsServicer.dto.clientobject.WaterSourceScreenCO;
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:50
 */
@Api(tags = "消防水源")
@RequestMapping("/${application.gateway}/waterSource")
@RestController
@AllArgsConstructor
public class WaterSourceController {
    private final WaterSourceServiceI waterSourceService;

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

    @ApiOperation("分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('xfsy')")
    public PageResponse<WaterSourceCO> page(@RequestBody WaterSourcePageQry qry) {
        return waterSourceService.listPage(qry);
    }

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

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

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

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

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody WaterSourceUpdateCmd waterSourceUpdateCmd) {
        waterSourceService.edit(waterSourceUpdateCmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("可视化大屏-消防水源查询")
    @PostMapping("/screenList")
    public PageResponse<WaterSourceScreenCO> screenList(@RequestBody WaterSourceScreenQry qry) {
        return waterSourceService.listScreen(qry);
    }
}
