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.AlarmRecordServiceI;
import com.zcloud.zcGbsServicer.dto.AlarmRecordAddCmd;
import com.zcloud.zcGbsServicer.dto.AlarmRecordClearCmd;
import com.zcloud.zcGbsServicer.dto.AlarmRecordHandleCmd;
import com.zcloud.zcGbsServicer.dto.AlarmRecordPageQry;
import com.zcloud.zcGbsServicer.dto.clientobject.AlarmRecordCO;
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.*;

@Api(tags = "消防报警记录")
@RestController
@AllArgsConstructor
@RequestMapping("/${application.gateway}/alarmRecord")
public class AlarmRecordController {

    private final AlarmRecordServiceI alarmRecordService;

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

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<AlarmRecordCO> save(@Validated @RequestBody AlarmRecordAddCmd cmd) {
        return alarmRecordService.add(cmd);
    }

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

    @ApiOperation("处置")
    @PostMapping("/handle")
    public Response handle(@Validated @RequestBody AlarmRecordHandleCmd cmd) {
        alarmRecordService.handle(cmd);
        return Response.buildSuccess();
    }

    @ApiOperation("消警")
    @PostMapping("/clear")
    public Response clear(@Validated @RequestBody AlarmRecordClearCmd cmd) {
        alarmRecordService.clear(cmd);
        return Response.buildSuccess();
    }
}
