export interface PropertyRecord {
  id: string;
  ownerName: string;
  address: Address;
  deedDate?: string;
  taxId?: string;
  propertyType: PropertyType;
  metadata?: Record<string, unknown>;
}

export interface Address {
  streetNumber: string;
  streetName: string;
  streetType?: string;
  unit?: string;
  city: string;
  state: string;
  zip: string;
  latitude?: number;
  longitude?: number;
}

export type PropertyType = 'residential' | 'commercial' | 'land' | 'multi-family';

export interface PropertySnapshot {
  id: string;
  propertyId: string;
  capturedAt: string;
  ownerName: string;
  address: Address;
  deedDate?: string;
  taxId?: string;
  propertyType: PropertyType;
  taxAmount?: number;
  lienCount?: number;
}

export interface MatchResult {
  nameScore: number;
  addressScore: number;
  overallConfidence: number;
  isMatch: boolean;
  details: MatchDetails;
}

export interface MatchDetails {
  nameNormalized: string[];
  addressNormalized: string[];
  levenshteinDistance: number;
  geocodingDistance?: number;
  fields: {
    firstName: FieldMatch;
    lastName: FieldMatch;
    middleName: FieldMatch;
    streetNumber: FieldMatch;
    streetName: FieldMatch;
    streetType: FieldMatch;
    unit: FieldMatch;
    city: FieldMatch;
    state: FieldMatch;
    zip: FieldMatch;
  };
}

export interface FieldMatch {
  valueA: string;
  valueB: string;
  normalizedA: string;
  normalizedB: string;
  score: number;
}

export interface ChangeDetectionResult {
  propertyId: string;
  changeType: ChangeType;
  severity: Severity;
  confidence: number;
  changes: PropertyChange[];
  previousSnapshot: PropertySnapshot;
  currentSnapshot: PropertySnapshot;
  detectedAt: string;
}

export type ChangeType = 'tax_change' | 'deed_change' | 'ownership_transfer' | 'lien_filing' | 'metadata_change';

export type Severity = 'minor' | 'moderate' | 'major';

export interface PropertyChange {
  field: string;
  oldValue: unknown;
  newValue: unknown;
  changeType: ChangeType;
}

export interface MatchingConfig {
  nameThreshold: number;
  addressThreshold: number;
  overallThreshold: number;
  geocodingRadiusMeters: number;
}

export interface DetectionConfig {
  ownershipNameThreshold: number;
  deedDateSensitivity: number;
  taxAmountChangePercent: number;
  severityOverrides?: Record<ChangeType, Severity>;
}

export interface NormalizedTokens {
  firstName: string;
  lastName: string;
  middleName: string;
  initials: string[];
}
