import type {
  AllocationType,
  ImportBatchStatus,
  OrderType,
  ResourceType,
  StagedRecordStatus,
  DispoImportSourceKind,
  DispoStagedRecordType,
  VacationType,
} from "./enums.js";

export interface ImportBatch {
  id: string;
  sourceSystem: string;
  status: ImportBatchStatus;
  referenceSourceFile?: string | null;
  planningSourceFile?: string | null;
  chargeabilitySourceFile?: string | null;
  notes?: string | null;
  summary: Record<string, unknown>;
  startedAt?: Date | null;
  stagedAt?: Date | null;
  approvedAt?: Date | null;
  committedAt?: Date | null;
  failedAt?: Date | null;
  createdAt: Date;
  updatedAt: Date;
}

export interface StagedTrace {
  importBatchId: string;
  status: StagedRecordStatus;
  sourceKind: DispoImportSourceKind;
  sourceWorkbook: string;
  sourceSheet: string;
  sourceRow: number;
  sourceColumn?: string | null;
  warnings: string[];
  errorMessage?: string | null;
  rawPayload: unknown;
  normalizedData: Record<string, unknown>;
  createdAt: Date;
  updatedAt: Date;
}

export interface StagedResource extends StagedTrace {
  id: string;
  canonicalExternalId: string;
  enterpriseId?: string | null;
  eid?: string | null;
  displayName?: string | null;
  email?: string | null;
  chapter?: string | null;
  chapterCode?: string | null;
  managementLevelGroupName?: string | null;
  managementLevelName?: string | null;
  countryCode?: string | null;
  metroCityName?: string | null;
  clientUnitName?: string | null;
  resourceType?: ResourceType | null;
  chargeabilityTarget?: number | null;
  fte?: number | null;
  lcrCents?: number | null;
  ucrCents?: number | null;
  availability?: Record<string, unknown> | null;
  roleTokens: string[];
}

export interface StagedClient extends StagedTrace {
  id: string;
  clientCode?: string | null;
  parentClientCode?: string | null;
  name: string;
  sortOrder?: number | null;
  isActive: boolean;
}

export interface StagedProject extends StagedTrace {
  id: string;
  projectKey: string;
  shortCode?: string | null;
  name?: string | null;
  clientCode?: string | null;
  utilizationCategoryCode?: string | null;
  orderType?: OrderType | null;
  allocationType?: AllocationType | null;
  winProbability?: number | null;
  isInternal: boolean;
  isTbd: boolean;
  startDate?: Date | null;
  endDate?: Date | null;
}

export interface StagedAssignment extends StagedTrace {
  id: string;
  resourceExternalId: string;
  projectKey?: string | null;
  assignmentDate?: Date | null;
  startDate?: Date | null;
  endDate?: Date | null;
  hoursPerDay?: number | null;
  percentage?: number | null;
  slotFraction?: number | null;
  roleToken?: string | null;
  roleName?: string | null;
  chapterToken?: string | null;
  utilizationCategoryCode?: string | null;
  winProbability?: number | null;
  isInternal: boolean;
  isUnassigned: boolean;
  isTbd: boolean;
}

export interface StagedVacation extends StagedTrace {
  id: string;
  resourceExternalId: string;
  vacationType: VacationType;
  startDate: Date;
  endDate: Date;
  note?: string | null;
  holidayName?: string | null;
  isHalfDay: boolean;
  halfDayPart?: string | null;
  isPublicHoliday: boolean;
}

export interface StagedAvailabilityRule extends StagedTrace {
  id: string;
  resourceExternalId: string;
  ruleType: string;
  weekday?: number | null;
  effectiveStartDate?: Date | null;
  effectiveEndDate?: Date | null;
  availableHours?: number | null;
  percentage?: number | null;
  isResolved: boolean;
}

export interface StagedUnresolvedRecord {
  id: string;
  importBatchId: string;
  status: StagedRecordStatus;
  sourceKind: DispoImportSourceKind;
  sourceWorkbook: string;
  sourceSheet: string;
  sourceRow: number;
  sourceColumn?: string | null;
  recordType: DispoStagedRecordType;
  resourceExternalId?: string | null;
  projectKey?: string | null;
  message: string;
  resolutionHint?: string | null;
  warnings: string[];
  rawPayload: unknown;
  normalizedData: Record<string, unknown>;
  createdAt: Date;
  updatedAt: Date;
}
