import { MockupLatentNeedProvider } from '../provider/MockupLatentNeedProvider'
import type { LatentNeedFilters } from '../provider/ILatentNeedProvider'
import type { LatentNeed } from '../domain/latentNeed'

const provider = MockupLatentNeedProvider

type ServiceResult<T> = { data: T; error: null } | { data: null; error: string }

export const latentNeedService = {
  async getPublicNeeds(filters?: LatentNeedFilters): Promise<ServiceResult<LatentNeed[]>> {
    try {
      const data = await provider.getAll(filters)
      return { data, error: null }
    } catch (e) {
      return { data: null, error: e instanceof Error ? e.message : 'Unbekannter Fehler' }
    }
  },

  async getNeedById(id: string): Promise<ServiceResult<LatentNeed | null>> {
    try {
      const data = await provider.getById(id)
      return { data, error: null }
    } catch (e) {
      return { data: null, error: e instanceof Error ? e.message : 'Unbekannter Fehler' }
    }
  },
}
