/**
 * 轮询告警管理 API
 */
import { BaseService } from '../BaseService'
import type { BaseResponse } from '@/types/api'
import type {
  PollingAlertRule,
  PollingAlertHistory,
  CreatePollingAlertRuleRequest,
  UpdatePollingAlertRuleRequest,
  PollingAlertHistoryQueryParams
} from '@/types/api/alert'

export class PollingAlertService extends BaseService {
  /**
   * 获取告警规则列表
   */
  static getPollingAlertRules(): Promise<BaseResponse<{ items: PollingAlertRule[] }>> {
    return this.get<BaseResponse<{ items: PollingAlertRule[] }>>('/api/admin/polling-alert-rules')
  }

  /**
   * 获取告警规则详情
   */
  static getPollingAlertRuleById(id: number): Promise<BaseResponse<PollingAlertRule>> {
    return this.get<BaseResponse<PollingAlertRule>>(`/api/admin/polling-alert-rules/${id}`)
  }

  /**
   * 创建告警规则
   */
  static createPollingAlertRule(
    data: CreatePollingAlertRuleRequest
  ): Promise<BaseResponse<PollingAlertRule>> {
    return this.post<BaseResponse<PollingAlertRule>>('/api/admin/polling-alert-rules', data)
  }

  /**
   * 更新告警规则
   */
  static updatePollingAlertRule(
    id: number,
    data: UpdatePollingAlertRuleRequest
  ): Promise<BaseResponse<null>> {
    return this.put<BaseResponse<null>>(`/api/admin/polling-alert-rules/${id}`, data)
  }

  /**
   * 删除告警规则
   */
  static deletePollingAlertRule(id: number): Promise<BaseResponse<null>> {
    return this.delete<BaseResponse<null>>(`/api/admin/polling-alert-rules/${id}`)
  }

  /**
   * 获取告警历史列表
   */
  static getPollingAlertHistory(params?: PollingAlertHistoryQueryParams): Promise<
    BaseResponse<{
      items: PollingAlertHistory[]
      page: number
      page_size: number
      total: number
      total_pages: number
    }>
  > {
    return this.get<
      BaseResponse<{
        items: PollingAlertHistory[]
        page: number
        page_size: number
        total: number
        total_pages: number
      }>
    >('/api/admin/polling-alert-history', params)
  }
}
