import type { IMarktHinweisProvider } from './IMarktHinweisProvider'
import type { MarktHinweis, CreateMarktHinweisInput } from '../domain/marktHinweis'
import { marktHinweise as seed } from '../mock-data/marktHinweise'

const store: MarktHinweis[] = [...seed]

export const MockupMarktHinweisProvider: IMarktHinweisProvider = {
  async getAll() {
    return [...store]
  },

  async getById(id: string) {
    return store.find(h => h.id === id) ?? null
  },

  async create(data: CreateMarktHinweisInput) {
    const next: MarktHinweis = {
      ...data,
      id: `mh-${Date.now()}`,
      createdAt: new Date().toISOString(),
      createdBy: 'Thomas Müller',
      verwaltungId: 'v-001',
      verwaltungName: 'Wincasa AG',
    }
    store.push(next)
    return next
  },

  async update(id: string, data: Partial<MarktHinweis>) {
    const idx = store.findIndex(h => h.id === id)
    if (idx === -1) throw new Error(`MarktHinweis ${id} not found`)
    const updated: MarktHinweis = { ...store[idx], ...data }
    store[idx] = updated
    return updated
  },
}
