export const SEARCH_REPOSITORY = Symbol('SEARCH_REPOSITORY');

export interface ListingDocument {
  id: string;
  listingId: string;
  propertyId: string;
  title: string;
  description: string;
  propertyType: string;
  transactionType: string;
  priceVND: number;
  pricePerM2: number | null;
  areaM2: number;
  bedrooms: number | null;
  bathrooms: number | null;
  floors: number | null;
  direction: string | null;
  address: string;
  ward: string;
  district: string;
  city: string;
  location: [number, number]; // [lat, lng]
  agentId: string | null;
  sellerId: string;
  status: string;
  publishedAt: number; // unix timestamp
  viewCount: number;
  saveCount: number;
  projectName: string | null;
  legalStatus: string | null;
  amenities: string[];
  isFeatured: number; // 1 if featuredUntil > now, 0 otherwise

  // Vietnamese diacritic-normalized fields for accent-insensitive search
  titleNormalized: string;
  descriptionNormalized: string;
  addressNormalized: string;
  wardNormalized: string;
  districtNormalized: string;
  cityNormalized: string;
  projectNameNormalized: string | null;
}

export interface SearchResult {
  hits: ListingDocument[];
  totalFound: number;
  page: number;
  perPage: number;
  totalPages: number;
  searchTimeMs: number;
}

export interface SearchParams {
  query?: string;
  filterBy?: string;
  sortBy?: string;
  page?: number;
  perPage?: number;
  geoDistanceField?: string;
  geoPoint?: { lat: number; lng: number };
  geoRadiusKm?: number;
}

export interface ISearchRepository {
  indexDocument(doc: ListingDocument): Promise<void>;
  indexDocuments(docs: ListingDocument[]): Promise<void>;
  removeDocument(id: string): Promise<void>;
  search(params: SearchParams): Promise<SearchResult>;
  ensureCollection(): Promise<void>;
  dropCollection(): Promise<void>;
}
