import type {
  DocumentLibraryBrand,
  DocumentLibraryProductType,
  DocumentLibraryType,
} from '@/features/foundation/document-library/types';

export type AssemblySourceType = 'generated' | 'document_library';

export interface AssemblySourcePolicy {
  sourceType: AssemblySourceType;
  role: string;
  required: boolean;
  order: number;
  documentType?: DocumentLibraryType;
}

export interface AssemblyPolicy {
  documentType: string;
  organizationId: string;
  productType?: DocumentLibraryProductType | null;
  brand?: DocumentLibraryBrand | null;
  language?: string | null;
  sources: AssemblySourcePolicy[];
}

export interface AssemblyWarning {
  code: 'missing_optional_source';
  role: string;
  message: string;
}

export interface ResolvedAssemblySource {
  role: string;
  sourceType: AssemblySourceType;
  required: boolean;
  order: number;
  fileName: string;
  contentType: string;
  checksum: string;
  pageCount: number;
  fileSize: number;
  metadata: Record<string, unknown>;
  buffer: Buffer;
}

export interface PersistedAssemblyArtifact {
  artifactId: string;
  storageKey: string;
  fileName: string;
  checksum: string;
  fileSize: number;
  pageCount: number;
}

export interface DocumentAssemblyResult {
  buffer: Buffer;
  fileName: string;
  checksum: string;
  fileSize: number;
  pageCount: number;
  policy: AssemblyPolicy;
  warnings: AssemblyWarning[];
  sources: ResolvedAssemblySource[];
  artifact: PersistedAssemblyArtifact | null;
}
