package com.qqchen.deploy.backend.deploy.api;

import com.qqchen.deploy.backend.deploy.dto.ServerAlertRuleDTO;
import com.qqchen.deploy.backend.deploy.entity.ServerAlertRule;
import com.qqchen.deploy.backend.deploy.query.ServerAlertRuleQuery;
import com.qqchen.deploy.backend.deploy.service.IServerAlertRuleService;
import com.qqchen.deploy.backend.framework.api.Response;
import com.qqchen.deploy.backend.framework.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * 服务器告警规则 Controller
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/server/alert-rule")
@Tag(name = "服务器告警规则管理", description = "服务器告警规则相关接口")
public class ServerAlertRuleApiController
    extends BaseController<ServerAlertRule, ServerAlertRuleDTO, Long, ServerAlertRuleQuery> {

    @Resource
    private IServerAlertRuleService alertRuleService;

    @Override
    @Operation(summary = "创建告警规则", description = "创建新的服务器告警规则")
    @PostMapping
    public Response<ServerAlertRuleDTO> create(@Validated @RequestBody ServerAlertRuleDTO dto) {
        return super.create(dto);
    }

    @Override
    @Operation(summary = "更新告警规则", description = "更新指定ID的告警规则")
    @PutMapping("/{id}")
    public Response<ServerAlertRuleDTO> update(
        @Parameter(description = "告警规则ID", required = true) @PathVariable Long id,
        @Validated @RequestBody ServerAlertRuleDTO dto
    ) {
        return super.update(id, dto);
    }

    @Override
    @Operation(summary = "删除告警规则", description = "删除指定ID的告警规则（逻辑删除）")
    @DeleteMapping("/{id}")
    public Response<Void> delete(
        @Parameter(description = "告警规则ID", required = true) @PathVariable Long id
    ) {
        return super.delete(id);
    }

    @Override
    @Operation(summary = "查询告警规则详情", description = "根据ID查询告警规则详情")
    @GetMapping("/{id}")
    public Response<ServerAlertRuleDTO> findById(
        @Parameter(description = "告警规则ID", required = true) @PathVariable Long id
    ) {
        return super.findById(id);
    }

    @Override
    @Operation(summary = "查询所有告警规则", description = "查询所有告警规则列表")
    @GetMapping
    public Response<List<ServerAlertRuleDTO>> findAll() {
        return super.findAll();
    }

    @Override
    @Operation(summary = "分页查询告警规则", description = "根据条件分页查询告警规则")
    @GetMapping("/page")
    public Response<Page<ServerAlertRuleDTO>> page(ServerAlertRuleQuery query) {
        return super.page(query);
    }

    @Override
    @Operation(summary = "条件查询告警规则列表", description = "根据条件查询告警规则列表")
    @GetMapping("/list")
    public Response<List<ServerAlertRuleDTO>> findAll(ServerAlertRuleQuery query) {
        return super.findAll(query);
    }

    @Override
    @Operation(summary = "批量处理告警规则", description = "批量创建/更新/删除告警规则")
    @PostMapping("/batch")
    public CompletableFuture<Response<Void>> batchProcess(@RequestBody List<ServerAlertRuleDTO> dtos) {
        return super.batchProcess(dtos);
    }

    @Override
    protected void exportData(HttpServletResponse response, List<ServerAlertRuleDTO> data) {
        log.info("导出告警规则数据，数据量：{}", data.size());
    }
}
