/**
 * Synor Storage SDK Types
 */

/** Pin status */
export type PinStatus = 'queued' | 'pinning' | 'pinned' | 'failed' | 'unpinned';

/** Hash algorithm */
export type HashAlgorithm = 'sha2-256' | 'blake3';

/** Entry type */
export type EntryType = 'file' | 'directory';

/** Match type for listing pins */
export type MatchType = 'exact' | 'iexact' | 'partial' | 'ipartial';

/** Storage SDK configuration */
export interface StorageConfig {
  apiKey: string;
  endpoint?: string;
  gateway?: string;
  pinningService?: string;
  chunkSize?: number;
  timeout?: number;
  debug?: boolean;
}

/** Upload options */
export interface UploadOptions {
  pin?: boolean;
  wrapWithDirectory?: boolean;
  cidVersion?: 0 | 1;
  hashAlgorithm?: HashAlgorithm;
  onProgress?: (progress: UploadProgress) => void;
}

/** Upload progress */
export interface UploadProgress {
  bytesUploaded: number;
  totalBytes: number;
  percentage: number;
}

/** Upload response */
export interface UploadResponse {
  cid: string;
  size: number;
  name?: string;
  hash?: string;
}

/** Download options */
export interface DownloadOptions {
  offset?: number;
  length?: number;
  onProgress?: (progress: DownloadProgress) => void;
}

/** Download progress */
export interface DownloadProgress {
  bytesDownloaded: number;
  totalBytes: number;
  percentage: number;
}

/** Pin information */
export interface Pin {
  cid: string;
  status: PinStatus;
  name?: string;
  size?: number;
  createdAt?: number;
  expiresAt?: number;
  delegates?: string[];
}

/** Pin request */
export interface PinRequest {
  cid: string;
  name?: string;
  duration?: number;
  origins?: string[];
}

/** List pins options */
export interface ListPinsOptions {
  status?: PinStatus[];
  match?: MatchType;
  name?: string;
  limit?: number;
  offset?: number;
}

/** List pins response */
export interface ListPinsResponse {
  pins: Pin[];
  total: number;
  hasMore: boolean;
}

/** Gateway URL */
export interface GatewayUrl {
  url: string;
  cid: string;
  path?: string;
}

/** CAR block */
export interface CarBlock {
  cid: string;
  data: string; // Base64-encoded
  size?: number;
}

/** CAR file */
export interface CarFile {
  version: 1 | 2;
  roots: string[];
  blocks?: CarBlock[];
  size?: number;
}

/** File entry for directory creation */
export interface FileEntry {
  name: string;
  content?: string | Buffer;
  cid?: string;
}

/** Directory entry */
export interface DirectoryEntry {
  name: string;
  cid: string;
  size?: number;
  type: EntryType;
}

/** Import CAR response */
export interface ImportCarResponse {
  roots: string[];
  blocksImported: number;
}

/** Storage statistics */
export interface StorageStats {
  totalSize: number;
  pinCount: number;
  bandwidth?: {
    upload: number;
    download: number;
  };
}

/** API error response */
export interface StorageError extends Error {
  statusCode: number;
  code?: string;
}
