package org.dromara.monitoring.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.monitoring.domain.bo.MonDevicePresetBo;
import org.dromara.monitoring.domain.dto.DelYzd;
import org.dromara.monitoring.domain.vo.MonDevicePresetVo;
import org.dromara.monitoring.service.IMonDevicePresetService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 摄像头预置位
 * 前端访问路由地址为:/camera/devicePreset
 *
 * @author LionLi
 * @date 2025-09-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/devicePreset")
public class MonDevicePresetController extends BaseController {

    private final IMonDevicePresetService monDevicePresetService;

    /**
     * 查询摄像头预置位列表
     */
    @SaCheckPermission("camera:devicePreset:list")
    @GetMapping("/list")
    public TableDataInfo<MonDevicePresetVo> list(MonDevicePresetBo bo, PageQuery pageQuery) {
        return monDevicePresetService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出摄像头预置位列表
     */
    @SaCheckPermission("camera:devicePreset:export")
    @Log(title = "摄像头预置位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MonDevicePresetBo bo, HttpServletResponse response) {
        List<MonDevicePresetVo> list = monDevicePresetService.queryList(bo);
        ExcelUtil.exportExcel(list, "摄像头预置位", MonDevicePresetVo.class, response);
    }

    /**
     * 获取摄像头预置位详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("camera:devicePreset:query")
    @GetMapping("/{id}")
    public R<MonDevicePresetVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(monDevicePresetService.queryById(id));
    }

    /**
     * 新增摄像头预置位
     */
    @SaCheckPermission("camera:devicePreset:add")
    @Log(title = "摄像头预置位", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MonDevicePresetBo bo) {
        return toAjax(monDevicePresetService.insertByBo(bo));
    }

    /**
     * 修改摄像头预置位
     */
    @SaCheckPermission("camera:devicePreset:edit")
    @Log(title = "摄像头预置位", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MonDevicePresetBo bo) {
        return toAjax(monDevicePresetService.updateByBo(bo));
    }

    /**
     * 删除摄像头预置位
     *
     * @param
     */
    @SaCheckPermission("camera:devicePreset:remove")
    @Log(title = "摄像头预置位", businessType = BusinessType.DELETE)
    @DeleteMapping("/delYzd")
    public R<Void> remove(@RequestBody List<DelYzd> yzd) {
        return toAjax(monDevicePresetService.deleteWithValidByIds(yzd, true));
    }

    @Log(title = "调用摄像头预置位", businessType = BusinessType.DELETE)
    @PostMapping("/callYzd")
    public R<Void> invoking(@RequestBody List<DelYzd> yzd) {
        return toAjax(monDevicePresetService.invoking(yzd));
    }




}
