import { MockupDataSourceProvider } from '../provider/MockupDataSourceProvider'
import type { DataSource, ConnectorRun, SourceStatus, TermsStatus, SourceFilters } from '../domain/dataSource'
import type { ListResponse, ItemResponse } from './types'

const provider = MockupDataSourceProvider

export const sourceService = {
  async getSources(filters?: SourceFilters): Promise<ListResponse<DataSource>> {
    const data = await provider.getSources(filters)
    return { data, meta: { total: data.length, page: 1, pageSize: data.length, hasMore: false } }
  },

  async getSource(id: string): Promise<ItemResponse<DataSource | null>> {
    const data = await provider.getSource(id)
    return { data }
  },

  async getConnectorRuns(sourceId: string): Promise<ListResponse<ConnectorRun>> {
    const data = await provider.getConnectorRuns(sourceId)
    return { data, meta: { total: data.length, page: 1, pageSize: data.length, hasMore: false } }
  },

  async triggerMockRun(sourceId: string): Promise<ItemResponse<ConnectorRun>> {
    const data = await provider.triggerMockRun(sourceId)
    return { data }
  },

  async updateSourceStatus(id: string, status: SourceStatus): Promise<ItemResponse<DataSource>> {
    const data = await provider.updateSourceStatus(id, status)
    return { data }
  },

  async markTermsStatus(id: string, termsStatus: TermsStatus): Promise<ItemResponse<DataSource>> {
    const data = await provider.markTermsStatus(id, termsStatus)
    return { data }
  },
}
