export type CsvPreviewStatus = 'PASS' | 'WARNING' | 'FAIL';

export type CsvPreviewAction = 'create' | 'update' | 'skip' | 'error';

export interface CsvPreviewError {
  file: string;
  row: number;
  column: string;
  code: string;
  message: string;
  suggestedFix: string;
}

export interface CsvPreviewWarning extends CsvPreviewError {}

export interface CsvTemplateDefinition {
  file: string;
  template: string;
  seedType: string;
  importOrder: number;
  supported: boolean;
  requiredColumns: string[];
  description: string;
  expectedHeaders: string[];
}

export interface CsvParsedRow {
  rowNumber: number;
  values: Record<string, string>;
  raw: string[];
}

export interface CsvParsedFile {
  fileName: string;
  template: CsvTemplateDefinition;
  headers: string[];
  rows: CsvParsedRow[];
  errors: CsvPreviewError[];
  warnings: CsvPreviewWarning[];
}

export interface CsvPreviewRow {
  row: number;
  status: CsvPreviewStatus;
  action: CsvPreviewAction;
  key: string | null;
  values: Record<string, string>;
  errors: CsvPreviewError[];
  warnings: CsvPreviewWarning[];
}

export interface CsvPreviewFileResult {
  fileName: string;
  template: string;
  importOrder: number;
  status: CsvPreviewStatus;
  summary: {
    rows: number;
    valid: number;
    warning: number;
    error: number;
    create: number;
    update: number;
    skip: number;
  };
  rows: CsvPreviewRow[];
  errors: CsvPreviewError[];
  warnings: CsvPreviewWarning[];
}

export interface CsvPreviewResult {
  summary: {
    files: number;
    rows: number;
    valid: number;
    warning: number;
    error: number;
    create: number;
    update: number;
    skip: number;
  };
  files: CsvPreviewFileResult[];
  generatedAt: string;
  previewHash: string;
}

export interface CsvPreviewFileInput {
  fileName: string;
  bytes: Uint8Array;
}

export interface CsvPreviewBatchIndex {
  organizations: Set<string>;
  users: Set<string>;
  memberships: Set<string>;
  roleAssignments: Set<string>;
  masterOptions: Set<string>;
  branches: Set<string>;
  productTypes: Set<string>;
  documentSequences: Set<string>;
  approvalWorkflows: Set<string>;
  approvalSteps: Set<string>;
  approvalMatrices: Set<string>;
  customers: Set<string>;
  contactsByEmail: Set<string>;
  contactsByName: Set<string>;
  contactShares: Set<string>;
  leads: Set<string>;
  opportunities: Set<string>;
  opportunityParties: Set<string>;
  quotations: Set<string>;
  quotationItems: Set<string>;
  quotationParties: Set<string>;
  quotationTopics: Set<string>;
  quotationTopicItems: Set<string>;
}
