package com.sz.admin.monitor.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sz.admin.monitor.pojo.dto.cameraalarm.CameraAlarmCreateDTO;
import com.sz.admin.monitor.pojo.dto.cameraalarm.CameraAlarmListDTO;
import com.sz.admin.monitor.pojo.dto.cameraalarm.CameraAlarmUpdateDTO;
import com.sz.admin.monitor.pojo.vo.cameraalarm.CameraAlarmVO;
import com.sz.admin.monitor.pojo.vo.edgebox.AlarmReportVO;
import com.sz.admin.monitor.service.CameraAlarmService;
import com.sz.core.common.entity.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 告警工单表 Controller
 * </p>
 *
 * @author Lz
 * @since 2026-02-10
 */
@Tag(name = "告警工单表")
@RestController
@RequestMapping("ry-camera-alarm")
@RequiredArgsConstructor
public class CameraAlarmController {

    private final CameraAlarmService cameraAlarmService;

    @Operation(summary = "新增")
    @SaCheckPermission(value = "ry.camera.alarm.create")
    @PostMapping
    public ApiResult<Void> create(@RequestBody CameraAlarmCreateDTO dto) {
        cameraAlarmService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改")
    @SaCheckPermission(value = "ry.camera.alarm.update")
    @PutMapping
    public ApiResult<Void> update(@RequestBody CameraAlarmUpdateDTO dto) {
        cameraAlarmService.update(dto);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @SaCheckPermission(value = "ry.camera.alarm.remove")
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody SelectIdsDTO dto) {
        cameraAlarmService.remove(dto);
        return ApiResult.success();
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission(value = "ry.camera.alarm.query_table")
    @GetMapping
    public ApiResult<PageResult<CameraAlarmVO>> list(CameraAlarmListDTO dto) {
        return ApiPageResult.success(cameraAlarmService.page(dto));
    }

    @Operation(summary = "详情")
    @SaCheckPermission(value = "ry.camera.alarm.query_table")
    @GetMapping("/{id}")
    public ApiResult<CameraAlarmVO> detail(@PathVariable Object id) {
        return ApiResult.success(cameraAlarmService.detail(id));
    }
    @Operation(summary = "根据id查询算法报警信息详情")
    @GetMapping("/get")
    public ApiResult<AlarmReportVO> getAlarmReportDetail(@RequestParam("id") Long id) {
        return ApiResult.success(cameraAlarmService.getAlarmReportDetail(id));
    }
    @Operation(summary = "导入")
    @Parameters({
        @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
    @SaCheckPermission(value = "ry.camera.alarm.import")
    @PostMapping("/import")
    public void importExcel(@ModelAttribute ImportExcelDTO dto) {
        cameraAlarmService.importExcel(dto);
    }

    @Operation(summary = "导出")
    @SaCheckPermission(value = "ry.camera.alarm.export")
    @PostMapping("/export")
    public void exportExcel(@RequestBody CameraAlarmListDTO dto, HttpServletResponse response) {
        cameraAlarmService.exportExcel(dto, response);
    }
}