import apiClient from '../client'
import type {
  DatasetCreateRequest,
  DatasetDetailResponse,
  DatasetListResponse,
  DatasetResponse,
  DatasetTrainRequest,
  TrainingTaskResponse,
} from '../types'

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

  create: async (req: DatasetCreateRequest): Promise<DatasetResponse> => {
    const { data } = await apiClient.post('/api/v1/admin/training/datasets', req)
    return data
  },

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

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

  trainFromDataset: async (
    datasetId: string,
    req: DatasetTrainRequest
  ): Promise<TrainingTaskResponse> => {
    const { data } = await apiClient.post(
      `/api/v1/admin/training/datasets/${datasetId}/train`,
      req
    )
    return data
  },
}
