package com.sz.admin.monitor.controller;

import com.sz.admin.monitor.pojo.dto.preset.PresetCreateDTO;
import com.sz.admin.monitor.pojo.dto.preset.PresetDeleteDTO;
import com.sz.admin.monitor.pojo.po.Preset;
import com.sz.admin.monitor.pojo.vo.Region.RegionVO;
import com.sz.admin.monitor.pojo.vo.preset.PresetVO;
import com.sz.admin.monitor.service.PresetService;
import com.sz.core.common.entity.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: PresetController
 * Package: com.sz.admin.monitor.controller
 * Description:
 */
@Tag(name = "preset 预置表")
@RestController
@RequestMapping("preset")
@RequiredArgsConstructor
@Profile({"dev", "local", "preview"})
public class PresetController {
    private final PresetService presetService;

    @Operation(summary = "查询已经设置的预置位")
    @GetMapping
    public ApiResult<List<PresetVO>> getPresetList(@RequestParam("id") Long id) {
        List<PresetVO> presetList = presetService.getPresetList(id);
        return ApiResult.success(presetList);
    }


    @Operation(summary = "查询数据库已经存在的预置位")
    @GetMapping("/list")
    public ApiResult<List<PresetVO>> getExistPresetList(@RequestParam("id")  Long id) {
        List<PresetVO> presetList = presetService.getExistPresetList(id);
        return ApiResult.success(presetList);
    }

    @Operation(summary = "删除预置位")
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody PresetDeleteDTO dto) {
        presetService.removePreset(dto);
        return ApiResult.success();
    }

    @Operation(summary = "保存预置位")
    @PostMapping
    public ApiResult<Void> create(@RequestBody PresetCreateDTO dto) {
        presetService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "详情")
    @GetMapping("/detail")
    public ApiResult<Preset> detail(@RequestParam("id") Long id,
                                    @RequestParam("presetIndex") Integer presetIndex) {
        return ApiResult.success(presetService.selectByCameraIdAndPresetIndex(id, presetIndex));
    }
}
