import type { ILatentNeedProvider, LatentNeedFilters } from './ILatentNeedProvider'
import type { LatentNeed } from '../domain/latentNeed'
import { mockLatentNeeds } from '../mock-data/latentNeeds'

const store: LatentNeed[] = [...mockLatentNeeds]

export const MockupLatentNeedProvider: ILatentNeedProvider = {
  async getAll(filters?: LatentNeedFilters): Promise<LatentNeed[]> {
    let results = [...store]
    if (filters?.assetType) results = results.filter(n => n.assetType === filters.assetType)
    if (filters?.status) results = results.filter(n => n.status === filters.status)
    return results.sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1))
  },
  async getById(id: string): Promise<LatentNeed | null> {
    return store.find(n => n.id === id) ?? null
  },
}
