package com.usky.sas.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.sas.domain.SasVideoMonitorGroupType;
import com.usky.sas.service.SasVideoMonitorGroupTypeService;
import com.usky.sas.service.vo.VideoMonitorGroupPageRequest;
import com.usky.sas.service.vo.VideoMonitorGroupSaveRequest;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 视频监控组配置接口
 *
 * GET /prod-api/service-sas/video/group/list  下拉列表
 * GET /prod-api/service-sas/video/group       分页
 * POST /prod-api/service-sas/video/group     新增
 * PUT /prod-api/service-sas/video/group/{id} 编辑
 * DELETE /prod-api/service-sas/video/group/{id} 删除
 */
@RestController
@RequestMapping("/video/group")
public class SasVideoMonitorGroupController {

    @Autowired
    private SasVideoMonitorGroupTypeService videoMonitorGroupTypeService;

    @GetMapping("/list")
    public ApiResult<List<SasVideoMonitorGroupType>> list() {
        return ApiResult.success(videoMonitorGroupTypeService.listAll());
    }

    @GetMapping
    public ApiResult<CommonPage<SasVideoMonitorGroupType>> page(VideoMonitorGroupPageRequest request) {
        return ApiResult.success(videoMonitorGroupTypeService.page(request));
    }

    @PostMapping
    public ApiResult<CreateResponse> create(@RequestBody VideoMonitorGroupSaveRequest request) {
        String id = videoMonitorGroupTypeService.create(request);
        CreateResponse resp = new CreateResponse();
        resp.setId(id);
        return ApiResult.success(resp);
    }

    @PutMapping("/{id}")
    public ApiResult<Void> update(@PathVariable("id") String id, @RequestBody VideoMonitorGroupSaveRequest request) {
        videoMonitorGroupTypeService.update(id, request);
        return ApiResult.success();
    }

    @DeleteMapping("/{id}")
    public ApiResult<Void> delete(@PathVariable("id") String id) {
        videoMonitorGroupTypeService.delete(id);
        return ApiResult.success();
    }

    @Data
    public static class CreateResponse {
        private String id;
    }
}
