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.SasAlarsasGroupType;
import com.usky.sas.service.SasAlarsasGroupTypeService;
import com.usky.sas.service.vo.AlarmGroupPageRequest;
import com.usky.sas.service.vo.AlarmGroupSaveRequest;
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;

/**
 * 报警联动配置接口
 *
 * 对应 API 文档：
 * GET /prod-api/service-sas/alarm/group
 * POST /prod-api/service-sas/alarm/group
 * PUT /prod-api/service-sas/alarm/group/{id}
 * DELETE /prod-api/service-sas/alarm/group/{id}
 */
@RestController
@RequestMapping("/alarm/group")
public class SasAlarmGroupController {

    @Autowired
    private SasAlarsasGroupTypeService alarsasGroupTypeService;

    @GetMapping
    public ApiResult<CommonPage<SasAlarsasGroupType>> page(AlarmGroupPageRequest request) {
        return ApiResult.success(alarsasGroupTypeService.page(request));
    }

    /** 报警联动组下拉列表（不分页） */
    @GetMapping("/list")
    public ApiResult<List<SasAlarsasGroupType>> list() {
        return ApiResult.success(alarsasGroupTypeService.list());
    }

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

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

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

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

