import type { Identifier } from './identifiers';
import type { AssetLike } from './assets';

export interface DocumentTag {
    id?: Identifier;
    label?: string | null;
    color?: string | null;
}

export interface DocumentCorrespondent {
    id?: Identifier;
    name?: string | null;
    count?: number;
}

export interface DocumentVersion {
    assets?: Record<string, AssetLike> | AssetLike[] | null;
    metadata?: Record<string, unknown> & { page_count?: number } | null;
    size_bytes?: number | string | null;
    checksum?: string | null;
    [key: string]: unknown;
}

export interface Document {
    id?: Identifier;
    title?: string | null;
    original_name?: string | null;
    filename?: string | null;
    mime_type?: string | null;

    issued_at?: string | number | null;
    created_at?: string | null;
    uploaded_at?: string | null;
    updated_at?: string | null;

    folder_id?: Identifier | null;
    folder_name?: string;
    folder_path?: string;

    tags?: DocumentTag[] | null;
    correspondents?: DocumentCorrespondent[] | null;

    current_version?: DocumentVersion | null;

    // Allow for other properties as we unify loosely typed interfaces
    [key: string]: unknown;
}

export interface Folder {
    id?: Identifier | 'root';
    name?: string;
}

export type FolderEntry = {
    type: 'folder';
    id: Identifier | 'root';
    key: string;
    folder: Folder;
};

export type DocumentEntry = {
    type: 'document';
    id: Identifier;
    key: string;
    document: Document;
};

export type DocumentsListEntry = FolderEntry | DocumentEntry;

// Event Handlers
import type { MouseEvent } from 'react';

export type FolderEventHandler = (folder: Folder, event: MouseEvent<HTMLElement>) => void;
export type DocumentEventHandler = (document: Document, event: MouseEvent<HTMLElement>) => void;
