import apiClient from '../client'
import type {
  ModelVersionListResponse,
  ModelVersionDetailResponse,
  ModelVersionResponse,
  ActiveModelResponse,
} from '../types'

export const modelsApi = {
  list: async (params?: {
    status?: string
    limit?: number
    offset?: number
  }): Promise<ModelVersionListResponse> => {
    const { data } = await apiClient.get('/api/v1/admin/training/models', {
      params,
    })
    return data
  },

  getDetail: async (versionId: string): Promise<ModelVersionDetailResponse> => {
    const { data } = await apiClient.get(`/api/v1/admin/training/models/${versionId}`)
    return data
  },

  getActive: async (): Promise<ActiveModelResponse> => {
    const { data } = await apiClient.get('/api/v1/admin/training/models/active')
    return data
  },

  activate: async (versionId: string): Promise<ModelVersionResponse> => {
    const { data } = await apiClient.post(`/api/v1/admin/training/models/${versionId}/activate`)
    return data
  },

  deactivate: async (versionId: string): Promise<ModelVersionResponse> => {
    const { data } = await apiClient.post(`/api/v1/admin/training/models/${versionId}/deactivate`)
    return data
  },

  archive: async (versionId: string): Promise<ModelVersionResponse> => {
    const { data } = await apiClient.post(`/api/v1/admin/training/models/${versionId}/archive`)
    return data
  },

  delete: async (versionId: string): Promise<{ message: string }> => {
    const { data } = await apiClient.delete(`/api/v1/admin/training/models/${versionId}`)
    return data
  },

  reload: async (): Promise<{ message: string; reloaded: boolean }> => {
    const { data } = await apiClient.post('/api/v1/admin/training/models/reload')
    return data
  },
}
