package com.sz.admin.monitor.controller;

import com.sz.admin.monitor.pojo.dto.nvr.NvrDTO;
import com.sz.admin.monitor.pojo.dto.nvr.NvrCreateDTO;
import com.sz.admin.monitor.pojo.dto.nvr.NvrListDTO;
import com.sz.admin.monitor.pojo.dto.nvr.NvrUpdateDTO;

import com.sz.admin.monitor.pojo.vo.nvr.NvrVO;
import com.sz.admin.monitor.service.NvrService;
import com.sz.core.common.entity.ApiPageResult;
import com.sz.core.common.entity.ApiResult;
import com.sz.core.common.entity.PageResult;
import com.sz.core.common.entity.SelectIdsDTO;
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: NvrController
 * Package: com.sz.admin.monitor.controller
 * Description:
 */
@Tag(name = "nvr 设备表")
@RestController
@RequestMapping("nvr")
@RequiredArgsConstructor
@Profile({"dev", "local", "preview"})
public class NvrController {
    private final NvrService nvrService;

    @Operation(summary = "新增")
    @PostMapping
    public ApiResult<Long> create(@RequestBody NvrCreateDTO dto) {
        return ApiResult.success( nvrService.create(dto));
    }

    @Operation(summary = "修改")
    @PutMapping
    public ApiResult<Void> update(@RequestBody NvrUpdateDTO dto) {
        nvrService.update(dto);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody SelectIdsDTO dto) {
        nvrService.remove(dto);
        return ApiResult.success();
    }

    @Operation(summary = "列表查询")
    @GetMapping
    public ApiResult<PageResult<NvrVO>> list(NvrListDTO dto) {
        return ApiPageResult.success(nvrService.page(dto));
    }

    @Operation(summary = "详情")
    @GetMapping("/{id}")
    public ApiResult<NvrVO> detail(@PathVariable Long id) {
        return ApiResult.success(nvrService.detail(id));
    }
    @Operation(summary = "获取指定节点下的所有NVR数据")
    @GetMapping("/under-node")
    public ApiResult<PageResult<NvrVO>> listByNode(@RequestParam("nodeId") Long nodeId,@RequestParam("type") Integer type,@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") int pageSize) {
        return ApiResult.success(nvrService.listByNode(nodeId,type,pageNum,pageSize));
    }

}
