import request from '@/utils/http'

export interface ModelRouteConditions {
  endpoints?: string[]
  api_key_ids?: string[]
  tenant_ids?: string[]
}

export interface ModelRouteRecord {
  id: string
  name: string
  source_model: string
  target_model: string
  provider_id: string
  provider_code: string
  weight: number
  priority: number
  conditions: ModelRouteConditions
  enabled: boolean
  created_at: string
  updated_at: string
}

export type ModelRouteInput = Omit<ModelRouteRecord, 'id' | 'provider_code' | 'created_at' | 'updated_at'>

export function fetchModelRoutes() {
  return request.get<ModelRouteRecord[]>({ url: '/api/v1/admin/model-routes' })
}

export function createModelRoute(data: ModelRouteInput) {
  return request.post<ModelRouteRecord>({ url: '/api/v1/admin/model-routes', params: data })
}

export function updateModelRoute(id: string, data: ModelRouteInput) {
  return request.put<ModelRouteRecord>({ url: `/api/v1/admin/model-routes/${id}`, params: data })
}

export function deleteModelRoute(id: string) {
  return request.del<{ deleted: boolean }>({ url: `/api/v1/admin/model-routes/${id}` })
}
