import type { LicitationCategory, LicitationProcedureType, LicitationSource, MunicipalOpenPortalType } from "@prisma/client";

export type MunicipalityConnectorInput = {
  id: string;
  stateCode: string;
  stateName: string;
  municipalityCode: string;
  municipalityName: string;
  openPortalUrl: string | null;
  openPortalType: MunicipalOpenPortalType;
  openSyncIntervalDays: number;
  lastOpenSyncAt: Date | null;
  pntSubjectId: string | null;
  pntEntityId: string | null;
  pntSectorId: string | null;
  pntEntryUrl: string | null;
  backupUrl: string | null;
  scrapingEnabled: boolean;
  isActive: boolean;
};

export type NormalizedDocument = {
  name: string;
  url: string;
  type?: string;
};

export type NormalizedLicitationInput = {
  sourceRecordId?: string | null;
  tenderCode?: string | null;
  procedureType: LicitationProcedureType;
  title: string;
  description?: string | null;
  category?: LicitationCategory | null;
  isOpen?: boolean;
  openingDate?: Date | null;
  closingDate?: Date | null;
  publishDate?: Date | null;
  eventDates?: Record<string, string> | null;
  amount?: number | null;
  currency?: string | null;
  status?: string | null;
  supplierAwarded?: string | null;
  documents?: NormalizedDocument[];
  rawSourceUrl?: string | null;
  rawPayload: Record<string, unknown>;
};

export type ConnectorResult = {
  source: LicitationSource;
  items: NormalizedLicitationInput[];
  rawSourceUrl?: string | null;
  warnings: string[];
};

export type SyncStats = {
  totalFetched: number;
  inserted: number;
  updated: number;
  skipped: number;
  errors: number;
  latestPublishDate: string | null;
};

export type RecommendationResultItem = {
  id: string;
  score: number;
  reasons: string[];
  title: string;
  description: string | null;
  amount: string | null;
  procedureType: string;
  category: string | null;
  publishDate: string | null;
  municipalityName: string;
  stateName: string;
  source: string;
  deterministicScore?: number;
  aiScore?: number;
  blendedScore?: number;
  aiReasons?: string[];
  aiRisks?: string[];
  nextStep?: string | null;
  suggestionId?: string | null;
};
