package com.sz.admin.monitor.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sz.admin.monitor.pojo.dto.edgebox.EdgeBoxBindCamerasDTO;
import com.sz.admin.monitor.pojo.dto.edgebox.EdgeBoxCreateDTO;
import com.sz.admin.monitor.pojo.dto.edgebox.EdgeBoxListDTO;
import com.sz.admin.monitor.pojo.dto.edgebox.EdgeBoxUpdateDTO;
import com.sz.admin.monitor.pojo.vo.edgebox.EdgeBoxVO;
import com.sz.admin.monitor.service.EdgeBoxService;
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.*;

/**
 * <p>
 * 边缘盒子 Controller
 * </p>
 *
 * @author Lz
 * @since 2026-03-05
 */
@Tag(name = "边缘盒子")
@RestController
@RequestMapping("ry-edge-box")
@RequiredArgsConstructor
public class EdgeBoxController {

    private final EdgeBoxService edgeBoxService;

    @Operation(summary = "新增")
    @SaCheckPermission(value = "ry.edge.box.create")
    @PostMapping
    public ApiResult<Void> create(@RequestBody EdgeBoxCreateDTO dto) {
        edgeBoxService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改")
    @SaCheckPermission(value = "ry.edge.box.update")
    @PutMapping
    public ApiResult<Void> update(@RequestBody EdgeBoxUpdateDTO dto) {
        edgeBoxService.update(dto);
        return ApiResult.success();
    }

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

    @Operation(summary = "列表查询")
    @SaCheckPermission(value = "ry.edge.box.query_table")
    @GetMapping
    public ApiResult<PageResult<EdgeBoxVO>> list(EdgeBoxListDTO dto) {
        return ApiPageResult.success(edgeBoxService.page(dto));
    }

    @Operation(summary = "详情")
    @SaCheckPermission(value = "ry.edge.box.query_table")
    @GetMapping("/{id}")
    public ApiResult<EdgeBoxVO> detail(@PathVariable Object id) {
        return ApiResult.success(edgeBoxService.detail(id));
    }

    @Operation(summary = "导入")
    @Parameters({
            @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
    @SaCheckPermission(value = "ry.edge.box.import")
    @PostMapping("/import")
    public void importExcel(@ModelAttribute ImportExcelDTO dto) {
        edgeBoxService.importExcel(dto);
    }

    @Operation(summary = "导出")
    @SaCheckPermission(value = "ry.edge.box.export")
    @PostMapping("/export")
    public void exportExcel(@RequestBody EdgeBoxListDTO dto, HttpServletResponse response) {
        edgeBoxService.exportExcel(dto, response);
    }

    @Operation(summary = "给盒子绑定摄像头通道")
    @PostMapping("/bind-cameras")
    public ApiResult<Void> bindCameras(@RequestBody EdgeBoxBindCamerasDTO dto) {
        edgeBoxService.bindCameras(dto);
        return ApiResult.success();
    }
}