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.FireCheckListServiceI;
import com.zcloud.fire.check.dto.*;
import com.zcloud.fire.check.dto.clientobject.FireCheckListCO;
import com.zcloud.fire.check.dto.clientobject.FireCheckListScreenCO;
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 javax.validation.constraints.NotNull;
import java.util.ArrayList;

/**
 * web-adapter
 *
 * @Author zhaokai
 * @Date 2025-11-28 10:32:08
 */
@Api(tags = "消防点位检查表")
@RequestMapping("/${application.gateway}/fireCheckList")
@RestController
@AllArgsConstructor
public class FireCheckListController {
    private final FireCheckListServiceI fireCheckListService;

    @ApiOperation("消防点检新增")
    @PostMapping("/save")
    public SingleResponse<FireCheckListCO> add(@Validated @RequestBody FireCheckListAddCmd cmd) {
        return fireCheckListService.add(cmd);
    }

    @ApiOperation("消防点检分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('xfdjb')")
    public PageResponse<FireCheckListCO> page(@RequestBody FireCheckListPageQry qry) {
        return fireCheckListService.listPage(qry);
    }


    @ApiOperation("消防点检详情")
    @GetMapping("/getInfoById/{id}")
    public SingleResponse<FireCheckListCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(fireCheckListService.getInfoById(id));
    }

    @ApiOperation("消防点检删除")
    @GetMapping("/remove/{id}")
    public Response remove(@PathVariable("id") Long id) {
        FireCheckListUpdateStateCmd fireCheckListUpdateStateCmd = new FireCheckListUpdateStateCmd();
        fireCheckListUpdateStateCmd.setId(id);
        fireCheckListUpdateStateCmd.setState(2);
        fireCheckListService.editState(fireCheckListUpdateStateCmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("消防点检删除多个")
    @PostMapping("/remove/ids")
    public Response removeBatch(@RequestBody FireCheckListRemoveCmd  cmd) {
        for (Long id : cmd.getIds()) {
            FireCheckListUpdateStateCmd fireCheckListUpdateStateCmd = new FireCheckListUpdateStateCmd();
            fireCheckListUpdateStateCmd.setId(id);
            fireCheckListUpdateStateCmd.setState(2);
            fireCheckListService.editState(fireCheckListUpdateStateCmd);
        }
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("消防点检修改")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody FireCheckListUpdateCmd fireCheckListUpdateCmd) {
        fireCheckListService.edit(fireCheckListUpdateCmd);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("消防点检修改状态")
    @PostMapping("/editState")
    public SingleResponse editState(@Validated @RequestBody FireCheckListUpdateStateCmd fireCheckListUpdateStateCmd) {
        fireCheckListService.editState(fireCheckListUpdateStateCmd);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("PC端-点位检查记录分页")
    @PostMapping("/checkListRecordList")
    @PreAuthorize("@pms.hasAnyPermission('dwjcjl')")
    public PageResponse<FireCheckListCO> checkListRecordList(@RequestBody FireCheckListRecordPageQry qry) {
        return fireCheckListService.checkListRecordList(qry);
    }
    @ApiOperation("股份端PC端-点位检查记录分页")
    @PostMapping("/mainCheckListRecordList")
    public PageResponse<FireCheckListCO> mainCheckListRecordList(@RequestBody FireCheckListRecordPageQry qry) {
        return fireCheckListService.checkListRecordList(qry);
    }

     @ApiOperation("可视化大屏-消防点检列表")
    @PostMapping("/screen/list")
    public PageResponse<FireCheckListScreenCO> screenList(@RequestBody(required = false) FireCheckListScreenQry qry) {
        return fireCheckListService.screenList(qry);
    }

}

