package routes

import (
	"github.com/gofiber/fiber/v2"

	"github.com/break/junhong_cmp_fiber/internal/handler/admin"
	"github.com/break/junhong_cmp_fiber/internal/model/dto"
	"github.com/break/junhong_cmp_fiber/pkg/openapi"
)

// registerPollingAlertRoutes 注册轮询告警路由
func registerPollingAlertRoutes(router fiber.Router, handler *admin.PollingAlertHandler, doc *openapi.Generator, basePath string) {
	// 告警规则管理
	rules := router.Group("/polling-alert-rules")
	rulesPath := basePath + "/polling-alert-rules"

	Register(rules, doc, rulesPath, "POST", "", handler.CreateRule, RouteSpec{
		Summary: "创建轮询告警规则",
		Tags:    []string{"轮询管理-告警"},
		Input:   new(dto.CreatePollingAlertRuleReq),
		Output:  new(dto.PollingAlertRuleResp),
		Auth:    true,
	})

	Register(rules, doc, rulesPath, "GET", "", handler.ListRules, RouteSpec{
		Summary: "获取轮询告警规则列表",
		Tags:    []string{"轮询管理-告警"},
		Input:   nil,
		Output:  new(dto.PollingAlertRuleListResp),
		Auth:    true,
	})

	Register(rules, doc, rulesPath, "GET", "/:id", handler.GetRule, RouteSpec{
		Summary: "获取轮询告警规则详情",
		Tags:    []string{"轮询管理-告警"},
		Input:   new(dto.IDReq),
		Output:  new(dto.PollingAlertRuleResp),
		Auth:    true,
	})

	Register(rules, doc, rulesPath, "PUT", "/:id", handler.UpdateRule, RouteSpec{
		Summary: "更新轮询告警规则",
		Tags:    []string{"轮询管理-告警"},
		Input:   new(dto.UpdatePollingAlertRuleParams),
		Output:  nil,
		Auth:    true,
	})

	Register(rules, doc, rulesPath, "DELETE", "/:id", handler.DeleteRule, RouteSpec{
		Summary: "删除轮询告警规则",
		Tags:    []string{"轮询管理-告警"},
		Input:   new(dto.IDReq),
		Output:  nil,
		Auth:    true,
	})

	// 告警历史
	historyPath := basePath + "/polling-alert-history"
	Register(router, doc, historyPath, "GET", "/polling-alert-history", handler.ListHistory, RouteSpec{
		Summary: "获取轮询告警历史",
		Tags:    []string{"轮询管理-告警"},
		Input:   new(dto.ListPollingAlertHistoryReq),
		Output:  new(dto.PollingAlertHistoryListResp),
		Auth:    true,
	})
}
