package com.sz.admin.monitor.controller;

import com.mybatisflex.core.query.QueryWrapper;
import com.sz.admin.monitor.pojo.dto.blurDetection.BlurDetectionDTO;
import com.sz.admin.monitor.pojo.dto.blurDetection.BlurDetectionUpdateDTO;
import com.sz.admin.monitor.pojo.po.BlurDetection;
import com.sz.admin.monitor.pojo.vo.blurDetection.BlurDetectionVO;
import com.sz.admin.monitor.service.BlurDetectionService;
import com.sz.core.common.entity.ApiResult;
import com.sz.core.util.BeanCopyUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: BlurDetectionController
 * Package: com.sz.admin.monitor.controller
 * Description:
 */
@Tag(name = "模糊检测")
@RestController
@RequestMapping("blur-detection")
@RequiredArgsConstructor
public class BlurDetectionController {
    private final BlurDetectionService blurDetectionService;

    /**
     * 新增模糊检测配置
     */
    @Operation(summary = "新增模糊检测配置")
    @PostMapping("/add")
    public ApiResult<Boolean> add(@RequestBody BlurDetectionDTO blurDetectionDTO) {
        BlurDetection detection = BeanCopyUtils.copy(blurDetectionDTO, BlurDetection.class);
        return ApiResult.success(blurDetectionService.save(detection));
    }

    /**
     * 更新配置信息
     */
    @Operation(summary = "更新配置信息")
    @PutMapping("/update")
    public ApiResult<Boolean> update(@RequestBody BlurDetectionUpdateDTO blurDetectionUpdateDTO) {
        return ApiResult.success(blurDetectionService.updateById(BeanCopyUtils.copy(blurDetectionUpdateDTO, BlurDetection.class)));
    }

    @Operation(summary = "新增或者更新配置信息")
    @PostMapping("/addOrUpdate")
    public ApiResult<Boolean> addOrUpdate(@RequestBody BlurDetectionDTO blurDetectionDTO) {
        return ApiResult.success(blurDetectionService.saveOrUpdateBlur(blurDetectionDTO));
    }

    @GetMapping("/get")
    @Operation(summary = "根据摄像头id查询模糊配置")
    public ApiResult<BlurDetectionVO> getById(@RequestParam Long id) {
        QueryWrapper wrapper = blurDetectionService.query().eq(BlurDetection::getCameraId, id);
        BlurDetection blurDetection = blurDetectionService.getOne(wrapper);
        if (blurDetection == null) {
            return ApiResult.success(null);
        }
        return ApiResult.success(BeanCopyUtils.copy(blurDetection, BlurDetectionVO.class));
    }


}
