export const DOCUMENT_LIBRARY_TYPES = [
  "sla",
  "warranty",
  "terms_conditions",
  "company_profile",
  "datasheet",
  "drawing",
  "certificate",
  "appendix",
  "safety_document",
  "installation_manual",
] as const;

export const DOCUMENT_LIBRARY_BRANDS = ["alla", "onvalla", "generic"] as const;
export const DOCUMENT_LIBRARY_LANGUAGES = ["th", "en"] as const;
export const DOCUMENT_LIBRARY_PRODUCT_TYPES = [
  "all",
  "crane",
  "dock_door",
  "solar",
  "service",
] as const;
export const DOCUMENT_LIBRARY_VERSION_STATUSES = [
  "draft",
  "published",
  "active",
  "archived",
] as const;

export type DocumentLibraryType = (typeof DOCUMENT_LIBRARY_TYPES)[number];
export type DocumentLibraryBrand = (typeof DOCUMENT_LIBRARY_BRANDS)[number];
export type DocumentLibraryLanguage =
  (typeof DOCUMENT_LIBRARY_LANGUAGES)[number];
export type DocumentLibraryProductType =
  (typeof DOCUMENT_LIBRARY_PRODUCT_TYPES)[number];
export type DocumentLibraryVersionStatus =
  (typeof DOCUMENT_LIBRARY_VERSION_STATUSES)[number];

export interface DocumentLibraryRecord {
  id: string;
  organizationId: string;
  code: string;
  name: string;
  documentType: DocumentLibraryType;
  description: string | null;
  brand: DocumentLibraryBrand;
  language: DocumentLibraryLanguage;
  productType: DocumentLibraryProductType;
  status: "active" | "inactive";
  isActive: boolean;
  createdBy: string;
  updatedBy: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
}

export interface DocumentLibraryVersionRecord {
  id: string;
  organizationId: string;
  libraryId: string;
  version: string;
  fileName: string;
  storageProvider: string;
  storageKey: string;
  mimeType: string;
  fileSize: number;
  checksum: string;
  pageCount: number;
  status: DocumentLibraryVersionStatus;
  isActive: boolean;
  publishedAt: string | null;
  publishedBy: string | null;
  archivedAt: string | null;
  archivedBy: string | null;
  createdBy: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
}

export interface DocumentLibraryListItem extends DocumentLibraryRecord {
  activeVersion: string | null;
  versionCount: number;
}

export interface DocumentLibraryDetail extends DocumentLibraryRecord {
  versions: DocumentLibraryVersionRecord[];
}

export interface DocumentLibraryFilters {
  documentType?: DocumentLibraryType;
  brand?: DocumentLibraryBrand;
  language?: DocumentLibraryLanguage;
  productType?: DocumentLibraryProductType;
  isActive?: "true" | "false";
}

export interface DocumentLibraryMutationPayload {
  code: string;
  name: string;
  documentType: DocumentLibraryType;
  description?: string | null;
  brand: DocumentLibraryBrand;
  language: DocumentLibraryLanguage;
  productType: DocumentLibraryProductType;
  isActive?: boolean;
}

export interface DocumentLibraryVersionUploadPayload {
  version: string;
  file: File;
}

export interface MutationSuccessResponse {
  success: boolean;
  message: string;
}

export interface DocumentLibraryListResponse extends MutationSuccessResponse {
  time: string;
  items: DocumentLibraryListItem[];
}

export interface DocumentLibraryDetailResponse extends MutationSuccessResponse {
  time: string;
  library: DocumentLibraryDetail;
}

export interface DocumentLibraryVersionActionResponse extends MutationSuccessResponse {
  version: DocumentLibraryVersionRecord;
}
