package com.zcloud.zcGbsServicer.web;

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.zcGbsServicer.api.FireBrigadeServiceI;
import com.zcloud.zcGbsServicer.dto.FireBrigadeAddCmd;
import com.zcloud.zcGbsServicer.dto.FireBrigadeOnlineStatusQry;
import com.zcloud.zcGbsServicer.dto.FireBrigadePageQry;
import com.zcloud.zcGbsServicer.dto.FireBrigadeUpdateCmd;
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeCO;
import com.zcloud.zcGbsServicer.dto.clientobject.FireBrigadeOnlineStatusCO;
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.List;

@Api(tags = "消防队伍")
@RestController
@AllArgsConstructor
@RequestMapping("/${application.gateway}/fireBrigade")
public class FireBrigadeController {

    private final FireBrigadeServiceI fireBrigadeService;

    @ApiOperation("分页查询")
    @PostMapping("/list")
    public PageResponse<FireBrigadeCO> list(@RequestBody FireBrigadePageQry qry) {
        return fireBrigadeService.listPage(qry);
    }

    @ApiOperation("批量刷新消防队伍在线状态缓存（供会议室等场景调用，可定时轮询）")
    @PostMapping("/online/status")
    public SingleResponse<List<FireBrigadeOnlineStatusCO>> onlineStatus(@RequestBody(required = false) FireBrigadeOnlineStatusQry qry) {
        return fireBrigadeService.queryOnlineStatus(qry == null ? new FireBrigadeOnlineStatusQry() : qry);
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<FireBrigadeCO> save(@Validated @RequestBody FireBrigadeAddCmd cmd) {
        return fireBrigadeService.add(cmd);
    }

    @ApiOperation("编辑")
    @PutMapping("/edit")
    public Response edit(@Validated @RequestBody FireBrigadeUpdateCmd cmd) {
        fireBrigadeService.edit(cmd);
        return Response.buildSuccess();
    }

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

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