import { MockupPropertyProvider } from '../provider/MockupPropertyProvider'
import type { PropertyFilters } from '../provider/IPropertyProvider'
import type { CreatePropertyInput, UpdatePropertyInput } from '../domain/property'
import type { ListResponse, ItemResponse } from './types'
import type { Property } from '../domain/property'

const provider = MockupPropertyProvider
const ACTIVE_STATUSES: readonly string[] = ['AVAILABLE_NOW', 'AVAILABLE_SOON']

export const propertyService = {
  async getAll(filters?: PropertyFilters): Promise<ListResponse<Property>> {
    const data = await provider.getAll(filters)
    return { data, meta: { total: data.length, page: 1, pageSize: data.length, hasMore: false } }
  },
  async getById(id: string): Promise<ItemResponse<Property | null>> {
    const data = await provider.getById(id)
    return { data }
  },
  async create(input: CreatePropertyInput): Promise<ItemResponse<Property>> {
    const data = await provider.create(input)
    return { data }
  },
  async update(id: string, input: UpdatePropertyInput): Promise<ItemResponse<Property>> {
    const data = await provider.update(id, input)
    return { data }
  },
  async remove(id: string): Promise<ItemResponse<void>> {
    await provider.remove(id)
    return { data: undefined }
  },

  async getDashboardPropertiesSummary(): Promise<{ total: number; active: number }> {
    const data = await provider.getAll()
    return {
      total: data.length,
      active: data.filter(p => ACTIVE_STATUSES.includes(p.availabilityStatus)).length,
    }
  },

  async getProperties(filters?: PropertyFilters): Promise<ListResponse<Property>> {
    const data = await provider.getAll(filters)
    return { data, meta: { total: data.length, page: 1, pageSize: data.length, hasMore: false } }
  },
}
