package org.dromara.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.domain.bo.SenEventsMediaBo;
import org.dromara.domain.vo.SenEventsMediaVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.domain.vo.SenMonitorPointMediaVo;
import org.dromara.domain.bo.SenMonitorPointMediaBo;
import org.dromara.service.ISenMonitorPointMediaService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 监控点位视频媒介
 *
 * @author luogang
 * @date 2024-09-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/manage/monitorPointMedia")
public class SenMonitorPointMediaController extends BaseController {

    private final ISenMonitorPointMediaService senMonitorPointMediaService;

    /**
     * 查询监控点位视频媒介列表
     */
    @SaCheckPermission("manage:monitorPointMedia:list")
    @GetMapping("/list")
    public TableDataInfo<SenMonitorPointMediaVo> list(SenMonitorPointMediaBo bo, PageQuery pageQuery) {
        return senMonitorPointMediaService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出监控点位视频媒介列表
     */
    @SaCheckPermission("manage:monitorPointMedia:export")
    @Log(title = "监控点位视频媒介", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SenMonitorPointMediaBo bo, HttpServletResponse response) {
        List<SenMonitorPointMediaVo> list = senMonitorPointMediaService.queryList(bo);
        ExcelUtil.exportExcel(list, "监控点位视频媒介", SenMonitorPointMediaVo.class, response);
    }

    /**
     * 获取监控点位视频媒介详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("manage:monitorPointMedia:query")
    @GetMapping("/{id}")
    public R<SenMonitorPointMediaVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(senMonitorPointMediaService.queryById(id));
    }

    /**
     * 新增监控点位视频媒介
     */
    @SaCheckPermission("manage:monitorPointMedia:add")
    @Log(title = "监控点位视频媒介", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SenMonitorPointMediaBo bo) {
        return toAjax(senMonitorPointMediaService.insertByBo(bo));
    }

    /**
     * 修改监控点位视频媒介
     */
    @SaCheckPermission("manage:monitorPointMedia:edit")
    @Log(title = "监控点位视频媒介", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SenMonitorPointMediaBo bo) {
        return toAjax(senMonitorPointMediaService.updateByBo(bo));
    }

    /**
     * 删除监控点位视频媒介
     *
     * @param ids 主键串
     */
    @SaCheckPermission("manage:monitorPointMedia:remove")
    @Log(title = "监控点位视频媒介", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(senMonitorPointMediaService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 获取事件媒介详细信息
     *
     * @param bo
     */
    @SaCheckPermission("manage:eventsMedia:query")
    @GetMapping("/getPointMediaByPointId")
    public R<SenMonitorPointMediaVo> getPointMediaByPointId(SenMonitorPointMediaBo bo) {
        return R.ok(senMonitorPointMediaService.getPointMediaByPointId(bo));
    }
}
