/**
 * 服务监测 - 目标管理 API
 */
import http from '@/utils/http'
import type {
  Target,
  CreateTargetRequest,
  UpdateTargetRequest,
  TestConnectionRequest,
  TestConnectionResponse,
} from '@/types/service-monitor'

/** 获取目标列表 */
export async function getTargets(): Promise<{ success: boolean; targets: Target[] }> {
  const res = await http.get<{ success: boolean; targets: Target[] }>('/api/service-monitor/targets')
  return res.data
}

/** 创建目标 */
export async function createTarget(data: CreateTargetRequest): Promise<{ success: boolean; target: Target }> {
  const res = await http.post<{ success: boolean; target: Target }>('/api/service-monitor/targets', data)
  return res.data
}

/** 更新目标 */
export async function updateTarget(
  targetId: string,
  data: UpdateTargetRequest
): Promise<{ success: boolean; target: Target }> {
  const res = await http.put<{ success: boolean; target: Target }>(
    `/api/service-monitor/targets/${targetId}`,
    data
  )
  return res.data
}

/** 删除目标 */
export async function deleteTarget(targetId: string): Promise<{ success: boolean }> {
  const res = await http.delete<{ success: boolean }>(`/api/service-monitor/targets/${targetId}`)
  return res.data
}

/** 测试连接 */
export async function testConnection(data: TestConnectionRequest): Promise<TestConnectionResponse> {
  const res = await http.post<TestConnectionResponse>('/api/service-monitor/targets/test', data)
  return res.data
}