/**
 * FormFileAttachment - File attachment type for hazo_files integration.
 *
 * Replaces the legacy FileData interface with a reference-tracking model.
 * Each attachment stores a file_id (the hazo_files record) and a ref_id
 * (the unique reference from an entity to that file), enabling multiple
 * fields to reference the same physical file without duplication.
 */
/**
 * Type guard: checks whether an object is a FormFileAttachment (vs legacy FileData).
 * FormFileAttachment has ref_id + mime_type; FileData has file_type + uploaded_at.
 */
export function is_form_file_attachment(item) {
    if (!item || typeof item !== 'object')
        return false;
    const obj = item;
    return typeof obj.ref_id === 'string' && typeof obj.mime_type === 'string';
}
/**
 * Convert a FormFileAttachment back to the legacy FileData shape.
 * Useful for consumers that still depend on FileData during migration.
 */
export function attachment_to_file_data(attachment) {
    return {
        file_id: attachment.file_id,
        file_name: attachment.file_name,
        file_size: attachment.file_size,
        file_type: attachment.mime_type,
        file_path: attachment.file_path ?? '',
        uploaded_at: new Date(attachment.attached_at),
        visibility: attachment.visibility,
    };
}
/**
 * Convert a legacy FileData to a FormFileAttachment.
 * A ref_id is required; if not provided, one will be generated.
 */
export function file_data_to_attachment(file_data, ref_id) {
    return {
        file_id: file_data.file_id,
        ref_id: ref_id ?? `migrated_${file_data.file_id}_${Date.now()}`,
        file_name: file_data.file_name,
        file_size: file_data.file_size,
        mime_type: file_data.file_type,
        visibility: file_data.visibility ?? 'public',
        attached_at: file_data.uploaded_at instanceof Date
            ? file_data.uploaded_at.toISOString()
            : typeof file_data.uploaded_at === 'string'
                ? file_data.uploaded_at
                : new Date().toISOString(),
        file_path: file_data.file_path,
    };
}
//# sourceMappingURL=file_attachment.js.map