import request from './request'

export interface DataSourceItem {
  id: number
  name: string
  source_type: string
  host?: string
  port?: number
  database_name?: string
  username?: string
  status: string
  created_at: string
}

export interface DataSourceForm {
  name: string
  source_type: string
  host?: string
  port?: number
  database_name?: string
  username?: string
  password?: string
  extra_params?: string
  dept_id?: number
}

export function getDataSources(params?: { page?: number; page_size?: number; keyword?: string }) {
  return request.get('/datasources', { params })
}

export function createDataSource(data: DataSourceForm) {
  return request.post('/datasources', data)
}

export function updateDataSource(id: number, data: Partial<DataSourceForm>) {
  return request.put(`/datasources/${id}`, data)
}

export function deleteDataSource(id: number) {
  return request.delete(`/datasources/${id}`)
}

export function testConnection(data: Partial<DataSourceForm>) {
  return request.post('/datasources/test-connection', data)
}

export function syncMetadata(sourceId: number) {
  return request.post(`/metadata/sync/${sourceId}`)
}
