import { request } from '@/api/request'

/** 获取通知渠道列表（分页） */
export const fetchNoticeChannelList = (data?: { page?: number; page_size?: number; keyword?: string; type?: string }) => {
  return request.get('/Alert/v1/channel/list', { params: data || {} })
}

/** 获取通知渠道详情 */
export const fetchNoticeChannelDetail = (id: number) => {
  return request.get(`/Alert/v1/channel/get/${id}`)
}

/** 创建通知渠道 */
export const createNoticeChannel = (data: {
  name: string
  type: string
  config: string
  message_template?: string
  rate_limit?: number
  rate_limit_window?: number
  severity_filter?: string
  quiet_hours?: string
  retry_times?: number
  retry_interval?: number
  enabled?: boolean
  description?: string
  email_smtp_host?: string
  email_smtp_port?: number
  email_username?: string
  email_password?: string
  email_from?: string
  email_to?: string[]
  email_cc?: string[]
  email_bcc?: string[]
  email_use_tls?: boolean
  sms_provider?: string
  sms_access_key_id?: string
  sms_access_key_secret?: string
  sms_sign_name?: string
  sms_template_code?: string
  sms_phones?: string[]
  in_app_targets?: string[]
}) => {
  return request.post('/Alert/v1/channel/create', data)
}

/** 更新通知渠道 */
export const updateNoticeChannel = (data: {
  id: number
  name?: string
  type?: string
  config?: string
  message_template?: string
  rate_limit?: number
  rate_limit_window?: number
  severity_filter?: string
  quiet_hours?: string
  retry_times?: number
  retry_interval?: number
  enabled?: boolean
  description?: string
  email_smtp_host?: string
  email_smtp_port?: number
  email_username?: string
  email_password?: string
  email_from?: string
  email_to?: string[]
  email_cc?: string[]
  email_bcc?: string[]
  email_use_tls?: boolean
  sms_provider?: string
  sms_access_key_id?: string
  sms_access_key_secret?: string
  sms_sign_name?: string
  sms_template_code?: string
  sms_phones?: string[]
  in_app_targets?: string[]
}) => {
  return request.post('/Alert/v1/channel/update', data)
}

/** 删除通知渠道 */
export const deleteNoticeChannel = (id: number) => {
  return request.delete(`/Alert/v1/channel/delete/${id}`)
}
