import { type PropertyType } from '@prisma/client';
import { type MarketIndexEntity } from '../entities/market-index.entity';
export const MARKET_INDEX_REPOSITORY = Symbol('MARKET_INDEX_REPOSITORY');

export interface MarketReportResult {
  district: string;
  city: string;
  propertyType: PropertyType;
  period: string;
  medianPrice: string;
  avgPriceM2: number;
  totalListings: number;
  daysOnMarket: number;
  inventoryLevel: number;
  absorptionRate: number | null;
  yoyChange: number | null;
}

export interface HeatmapDataPoint {
  district: string;
  city: string;
  avgPriceM2: number;
  totalListings: number;
  medianPrice: string;
}

/** [TEC-3055] Ward-level heatmap data point */
export interface WardHeatmapDataPoint {
  ward: string;
  district: string;
  city: string;
  avgPriceM2: number;
  totalListings: number;
  medianPrice: string;
}

/** [TEC-3055] Ward-level listing volume result */
export interface ListingVolumeWardResult {
  ward: string;
  district: string;
  city: string;
  period: string;
  totalListings: number;
  avgPriceM2: number;
  medianPrice: string;
}

export interface PriceTrendPoint {
  period: string;
  medianPrice: string;
  avgPriceM2: number;
  totalListings: number;
}

export interface DistrictStatsResult {
  district: string;
  city: string;
  propertyType: PropertyType;
  medianPrice: string;
  avgPriceM2: number;
  totalListings: number;
  daysOnMarket: number;
  inventoryLevel: number;
  absorptionRate: number | null;
  yoyChange: number | null;
}

export interface MarketHistoryPoint {
  date: string;
  avgPrice: number;
  medianPrice: string;
  listingsCount: number;
  inquiriesCount: number;
  daysOnMarket: number;
}

export interface IMarketIndexRepository {
  findById(id: string): Promise<MarketIndexEntity | null>;
  findByKey(district: string, city: string, propertyType: PropertyType, period: string): Promise<MarketIndexEntity | null>;
  save(entity: MarketIndexEntity): Promise<void>;
  update(entity: MarketIndexEntity): Promise<void>;
  getMarketReport(city: string, period: string, propertyType?: PropertyType): Promise<MarketReportResult[]>;
  getHeatmap(city: string, period: string): Promise<HeatmapDataPoint[]>;
  /** [TEC-3055] Ward-level heatmap tile aggregation */
  getHeatmapWard(city: string, period: string, district?: string): Promise<WardHeatmapDataPoint[]>;
  /** [TEC-3055] Listing volume + avg price by ward for a time period */
  getListingVolumeByWard(wardId: string, period: string): Promise<ListingVolumeWardResult | null>;
  getPriceTrend(district: string, city: string, propertyType: PropertyType, periods: string[]): Promise<PriceTrendPoint[]>;
  getDistrictStats(city: string, period: string): Promise<DistrictStatsResult[]>;
  getMarketHistory(city: string, periods: string[]): Promise<MarketHistoryPoint[]>;
}
