/**
 * 服务监测 - 通知配置 API
 */
import http from '@/utils/http'
import type { NotificationConfig, NotificationConfigResponse } from '@/types/service-monitor'

/** 获取通知配置 */
export async function getNotificationConfig(): Promise<NotificationConfigResponse> {
  const res = await http.get<NotificationConfigResponse>('/api/service-monitor/notification')
  return res.data
}

/** 保存通知配置 */
export async function saveNotificationConfig(
  data: NotificationConfig
): Promise<NotificationConfigResponse> {
  const res = await http.put<NotificationConfigResponse>(
    '/api/service-monitor/notification',
    data
  )
  return res.data
}

/** 测试邮件通知 */
export async function testEmail(): Promise<{ success: boolean; message: string }> {
  const res = await http.post<{ success: boolean; message: string }>(
    '/api/service-monitor/notification/test-email'
  )
  return res.data
}

/** 测试钉钉通知 */
export async function testDingTalk(): Promise<{ success: boolean; message: string }> {
  const res = await http.post<{ success: boolean; message: string }>(
    '/api/service-monitor/notification/test-dingtalk'
  )
  return res.data
}

/** 测试企业微信通知 */
export async function testWeCom(): Promise<{ success: boolean; message: string }> {
  const res = await http.post<{ success: boolean; message: string }>(
    '/api/service-monitor/notification/test-wecom'
  )
  return res.data
}

/** 检查缺失报告的目标 */
export async function checkMissingReports(): Promise<{
  success: boolean
  data: { missing_targets: Array<{ target_name: string; target_id: string; last_report_at: string | null; missing_days: number }> }
}> {
  const res = await http.get('/api/service-monitor/notification/check-missing-reports')
  return res.data
}