import { type PropertyType } from '@prisma/client';

export const AVM_SERVICE = Symbol('AVM_SERVICE');

export type FloodZoneRisk = 'NONE' | 'LOW' | 'MEDIUM' | 'HIGH';

export interface AVMParams {
  propertyId?: string;
  latitude?: number;
  longitude?: number;
  areaM2?: number;
  propertyType?: PropertyType;
  yearBuilt?: number;
  floor?: number;
  totalFloors?: number;

  // ── Optional inline descriptors (used when no propertyId is given) ──
  district?: string;
  city?: string;
  bedrooms?: number;
  bathrooms?: number;
  floors?: number;
  frontage?: number;
  roadWidth?: number;
  hasLegalPaper?: boolean;
  projectId?: string;
  imageUrl?: string;
  description?: string;
  deepAnalysis?: boolean;

  // ── AVM v2 features ────────────────────────────────────────────────
  useV2?: boolean;
  distanceToHospitalKm?: number;
  distanceToParkKm?: number;
  distanceToMallKm?: number;
  floodZoneRisk?: FloodZoneRisk;
  hasElevator?: boolean;
  hasParking?: boolean;
  hasPool?: boolean;
}

export interface Comparable {
  propertyId: string;
  address: string;
  district: string;
  priceVND: string;
  pricePerM2: number;
  areaM2: number;
  propertyType: PropertyType;
  distanceMeters: number;
  soldAt: string;
}

export interface ValuationResult {
  estimatedPrice: string;
  confidence: number;
  pricePerM2: number;
  comparables: Comparable[];
  modelVersion: string;
  confidenceExplanation?: string;
}

export interface BatchValuationItem {
  propertyId: string;
}

export interface BatchValuationResult {
  propertyId: string;
  valuation: ValuationResult | null;
  error?: string;
}

export interface ValuationHistoryPoint {
  estimatedPrice: string;
  confidence: number;
  pricePerM2: number;
  modelVersion: string;
  valuedAt: string;
}

export interface ValuationComparisonItem {
  propertyId: string;
  address: string;
  district: string;
  areaM2: number;
  propertyType: PropertyType;
  valuation: ValuationResult | null;
}

export interface IAVMService {
  estimateValue(params: AVMParams): Promise<ValuationResult>;
  getComparables(propertyId: string, radiusMeters: number): Promise<Comparable[]>;
  estimateBatch(items: BatchValuationItem[]): Promise<BatchValuationResult[]>;
}
