import { type DeclaredMimeType, type DetectedMimeType, type FileChecksumSha256, type NonEmptyArray, type OriginalFilename, type PositiveByteCount, type Result, type SafeDownloadFilename, type SiteId, type StorageBucketName, type StoragePath, type UploadSessionId, type UserId, type UtcIsoDateTimeString } from '@riverbankcms/core';
import { type AccessPolicy, type ActiveFileAssetValidationError, type ActiveValidatedFileAsset, type FileAsset, type FileActor, type FileDerivative, type FileKind, type FileUse, type StorageClass, type UploadSessionState, type UploadSessionStateTag, type UploadIntent, type UploadPolicy, type UploadPolicyDetection } from './fileDomain';
export type FileKindJson = FileJsonObject;
export type FileUseJson = FileJsonObject;
export type FileUsesJson = readonly FileUseJson[];
export type FileActorJson = FileJsonObject;
export type UploadIntentJson = FileJsonObject;
export type AccessPolicyJson = FileJsonObject;
export type UploadPolicyJson = FileJsonObject;
export type FileDomainJson = FileJsonObject | readonly FileJsonValue[];
export type FileDomainJsonParseError = 'expected-object' | 'expected-array' | 'expected-non-empty-array' | 'invalid-tag' | 'invalid-field' | 'invalid-string' | 'invalid-number' | 'invalid-positive-byte-count' | 'invalid-positive-seconds' | 'invalid-timestamp' | 'invalid-checksum' | 'invalid-safe-download-filename' | 'missing-state-timestamp' | 'missing-finalized-asset' | 'missing-rejection-reason';
export type FileUploadSessionRecordError = 'actor-site-mismatch' | 'policy-intent-mismatch';
export type FileJsonValue = string | number | boolean | null | FileJsonObject | readonly FileJsonValue[];
export type FileJsonObject = {
    readonly [key: string]: FileJsonValue;
};
export type FileUploadSessionRow = {
    readonly id: string;
    readonly site_id: string;
    readonly actor: unknown;
    readonly intent: unknown;
    readonly policy: unknown;
    readonly staged_storage_bucket: string;
    readonly staged_storage_path: string;
    readonly state: string;
    readonly original_filename: string;
    readonly safe_download_filename: string | null;
    readonly declared_mime_type: string | null;
    readonly detected_mime_type: string | null;
    readonly byte_count: number | null;
    readonly checksum_sha256: string | null;
    readonly expires_at: string;
    readonly uploaded_at: string | null;
    readonly finalizing_started_at: string | null;
    readonly finalized_at: string | null;
    readonly rejected_at: string | null;
    readonly expired_at: string | null;
    readonly cleaned_up_at: string | null;
    readonly finalized_asset_id: string | null;
    readonly rejection_reason: string | null;
    readonly created_by: string | null;
    readonly created_at: string;
    readonly updated_at: string;
};
export type FileUploadSessionRecord = {
    readonly id: UploadSessionId;
    readonly siteId: SiteId;
    readonly actor: FileActor;
    readonly intent: UploadIntent;
    readonly policy: UploadPolicy;
    readonly stagedStorageBucket: StorageBucketName;
    readonly stagedStoragePath: StoragePath;
    readonly state: UploadSessionState;
    readonly originalFilename: OriginalFilename;
    readonly safeDownloadFilename?: SafeDownloadFilename;
    readonly declaredMimeType?: DeclaredMimeType;
    readonly detectedMimeType?: DetectedMimeType;
    readonly byteCount?: PositiveByteCount;
    readonly checksumSha256?: FileChecksumSha256;
    readonly createdBy?: UserId;
    readonly createdAt: UtcIsoDateTimeString;
    readonly updatedAt: UtcIsoDateTimeString;
};
export type FileAssetRecordError = {
    readonly tag: 'invalid-file-asset';
    readonly error: ActiveFileAssetValidationError;
} | {
    readonly tag: 'invalid-json-metadata';
    readonly field: 'exif';
};
export type FileAssetInsertRow = {
    readonly id: FileAsset['id'];
    readonly site_id: FileAsset['siteId'];
    readonly storage_bucket: FileAsset['storageBucket'];
    readonly storage_path: FileAsset['storagePath'];
    readonly filename: FileAsset['filename'];
    readonly mime_type: FileAsset['mimeType'];
    readonly file_kind: FileKindJson;
    readonly file_uses: FileUsesJson;
    readonly access_policy: AccessPolicyJson;
    readonly storage_class: StorageClass;
    readonly safe_download_filename: SafeDownloadFilename | null;
    readonly bytes: PositiveByteCount | null;
    readonly checksum_sha256: FileChecksumSha256 | null;
    readonly lifecycle_state: FileAssetLifecycleState;
    readonly source: 'upload' | 'instagram';
    readonly created_by: UserId | null;
    readonly width: number | null;
    readonly height: number | null;
    readonly duration_seconds: number | null;
    readonly thumbnail_asset_id: FileAsset['id'] | null;
    readonly is_thumbnail: boolean;
    readonly alt_text: string | null;
    readonly caption: string | null;
    readonly exif: FileJsonObject | null;
    readonly title: string | null;
    readonly origin_asset_id: FileAsset['id'] | null;
    readonly derivative_kind: FileDerivative['tag'] | null;
};
export type FileAssetLifecycleState = ActiveValidatedFileAsset['lifecycle']['tag'];
export type FileAssetRow = {
    readonly id: string;
    readonly site_id: string;
    readonly storage_bucket: string;
    readonly storage_path: string;
    readonly filename: string;
    readonly mime_type: string;
    readonly file_kind: unknown;
    readonly file_uses: unknown;
    readonly access_policy: unknown;
    readonly storage_class: string;
    readonly safe_download_filename: string | null;
    readonly bytes: number | null;
    readonly checksum_sha256: string | null;
    readonly lifecycle_state: string;
    readonly source: string;
    readonly created_by: string | null;
    readonly created_at: string;
    readonly updated_at: string;
    readonly width: number | null;
    readonly height: number | null;
    readonly duration_seconds: number | null;
    readonly thumbnail_asset_id: string | null;
    readonly is_thumbnail: boolean | null;
    readonly alt_text: string | null;
    readonly caption: string | null;
    readonly exif: unknown;
    readonly title: string | null;
    readonly origin_asset_id: string | null;
    readonly derivative_kind: string | null;
};
export type FileAssetRowParseError = {
    readonly tag: 'invalid-row-string';
    readonly field: FileAssetRowStringField;
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-file-kind';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-file-uses';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-access-policy';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-storage-class';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-lifecycle-state';
    readonly lifecycleState: string;
} | {
    readonly tag: 'invalid-source';
    readonly source: string;
} | {
    readonly tag: 'invalid-derivative-source';
    readonly source: string;
    readonly derivativeKind: FileDerivative['tag'];
} | {
    readonly tag: 'missing-derivative-origin';
    readonly derivativeKind: FileDerivative['tag'];
} | {
    readonly tag: 'invalid-safe-download-filename';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-byte-count';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-checksum';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-created-at';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-updated-at';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-exif';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-derivative-kind';
    readonly error: FileDomainJsonParseError;
} | {
    readonly tag: 'invalid-file-asset';
    readonly error: ActiveFileAssetValidationError;
};
export type FileAssetRowStringField = 'id' | 'site_id' | 'storage_bucket' | 'storage_path' | 'filename' | 'mime_type' | 'created_by';
export type FileUploadSessionInsertRow = Omit<FileUploadSessionRow, 'actor' | 'intent' | 'policy' | 'state' | 'created_at' | 'updated_at'> & {
    readonly actor: FileActorJson;
    readonly intent: UploadIntentJson;
    readonly policy: UploadPolicyJson;
    readonly state: UploadSessionStateTag;
};
export type FileUploadSessionStatePersistencePatch = Pick<FileUploadSessionInsertRow, 'state' | 'uploaded_at' | 'finalizing_started_at' | 'finalized_at' | 'rejected_at' | 'expired_at' | 'cleaned_up_at' | 'finalized_asset_id' | 'rejection_reason'>;
type TagOnlyCheck<T extends {
    readonly tag: string;
}> = T extends unknown ? Exclude<keyof T, 'tag'> extends never ? true : false : never;
type AssertTagOnly<T extends {
    readonly tag: string;
}> = false extends TagOnlyCheck<T> ? never : true;
export type AssertFinalizeModeStaysTagOnly = AssertTagOnly<UploadPolicy['finalizeMode']>;
export type AssertDetectionStaysTagOnly = AssertTagOnly<UploadPolicyDetection>;
export type AssertPostProcessStaysTagOnly = AssertTagOnly<UploadPolicy['postProcess']>;
export declare function fileKindToJson(kind: FileKind): FileKindJson;
export declare function fileUseToJson(use: FileUse): FileUseJson;
export declare function fileUsesToJson(uses: NonEmptyArray<FileUse>): FileUsesJson;
export declare function fileAssetRecordToInsertRow(asset: FileAsset): Result<FileAssetInsertRow, FileAssetRecordError>;
export declare function parseFileAssetRow(row: FileAssetRow): Result<ActiveValidatedFileAsset, FileAssetRowParseError>;
export declare function fileActorToJson(actor: FileActor): FileActorJson;
export declare function uploadIntentToJson(intent: UploadIntent): UploadIntentJson;
export declare function uploadSessionStateToPersistencePatch(state: UploadSessionState): FileUploadSessionStatePersistencePatch;
export declare function fileUploadSessionRecordToInsertRow(record: FileUploadSessionRecord): Result<FileUploadSessionInsertRow, FileUploadSessionRecordError>;
export declare function parseFileUploadSessionRow(row: FileUploadSessionRow): Result<FileUploadSessionRecord, FileDomainJsonParseError>;
export declare function parseUploadSessionStateRow(row: Pick<FileUploadSessionRow, 'state' | 'expires_at' | 'uploaded_at' | 'finalizing_started_at' | 'finalized_at' | 'rejected_at' | 'expired_at' | 'cleaned_up_at' | 'finalized_asset_id' | 'rejection_reason'>): Result<UploadSessionState, FileDomainJsonParseError>;
export declare function accessPolicyToJson(policy: AccessPolicy): AccessPolicyJson;
export declare function uploadPolicyToJson(policy: UploadPolicy): UploadPolicyJson;
export declare function parseFileKindJson(value: unknown): Result<FileKind, FileDomainJsonParseError>;
export declare function parseFileUseJson(value: unknown): Result<FileUse, FileDomainJsonParseError>;
export declare function parseFileUsesJson(value: unknown): Result<NonEmptyArray<FileUse>, FileDomainJsonParseError>;
export declare function parseFileActorJson(value: unknown): Result<FileActor, FileDomainJsonParseError>;
export declare function parseUploadIntentJson(value: unknown): Result<UploadIntent, FileDomainJsonParseError>;
export declare function parseAccessPolicyJson(value: unknown): Result<AccessPolicy, FileDomainJsonParseError>;
export declare function parseUploadPolicyJson(value: unknown): Result<UploadPolicy, FileDomainJsonParseError>;
export {};
