import type { AddLinksPayload, AccountCheckScope, AccountCommandResult, AccountCredentialCheckInput, AccountSecretRequest, AccountSecretResult, ArchivePasswordListResult, AccountCreateCommand, AccountDeleteCommand, AccountReplaceCommand, AccountUpdateSecretCommand, AllDebridHostInfo, DebridAccountStatus, DebugSetupCheckResult, DebridLinkHostLimitInfo, DebridProvider, DuplicatePolicy, EnableRemoteDiagnosticsInput, HistoryEntry, HistoryRevealResult, PackagePriority, RemoteDiagnosticsInfo, RendererSettings, RendererSettingsUpdate, RendererErrorReport, SessionStats, StartConflictEntry, StartConflictResolutionResult, SupportTraceConfig, UiSnapshot, UpdateCheckResult, UpdateInstallProgress, UpdateInstallResult } from "./types"; import { isRealDebridWebAccountId } from "./real-debrid-accounts"; export interface RealDebridLoginRequest { accountId: string; create?: boolean; dailyLimitBytes?: number; } export function validateRealDebridLoginRequest(value: unknown): Required { if (!value || typeof value !== "object" || Array.isArray(value)) { throw new Error("Account-Payload ist ungültig"); } const raw = value as Record; if (Object.keys(raw).some((key) => key !== "accountId" && key !== "create" && key !== "dailyLimitBytes") || typeof raw.accountId !== "string" || !isRealDebridWebAccountId(raw.accountId) || (raw.create !== undefined && typeof raw.create !== "boolean") || (raw.dailyLimitBytes !== undefined && (typeof raw.dailyLimitBytes !== "number" || !Number.isFinite(raw.dailyLimitBytes) || raw.dailyLimitBytes < 0 || raw.dailyLimitBytes > Number.MAX_SAFE_INTEGER))) { throw new Error("Account-Payload ist ungültig"); } const create = raw.create === true; const dailyLimitBytes = Math.floor(Number(raw.dailyLimitBytes) || 0); if (!create && dailyLimitBytes !== 0) { throw new Error("Account-Payload ist ungültig"); } return { accountId: raw.accountId.trim(), create, dailyLimitBytes: create ? dailyLimitBytes : 0 }; } export interface ElectronApi { getSnapshot: () => Promise; getVersion: () => Promise; checkUpdates: () => Promise; installUpdate: () => Promise; openExternal: (url: string) => Promise; updateSettings: (settings: RendererSettingsUpdate) => Promise; resetProviderDailyUsage: (provider: DebridProvider) => Promise; resetDebridLinkApiKeyDailyUsage: (keyId: string) => Promise; createAccount: (command: AccountCreateCommand) => Promise; replaceAccount: (command: AccountReplaceCommand) => Promise; updateAccountSecret: (command: AccountUpdateSecretCommand) => Promise; deleteAccount: (command: AccountDeleteCommand) => Promise; addLinks: (payload: AddLinksPayload) => Promise<{ addedPackages: number; addedLinks: number; invalidCount: number }>; addContainers: (filePaths: string[]) => Promise<{ addedPackages: number; addedLinks: number }>; getStartConflicts: () => Promise; resolveStartConflict: (packageId: string, policy: DuplicatePolicy) => Promise; clearAll: () => Promise; start: () => Promise; startPackages: (packageIds: string[]) => Promise; stop: () => Promise; togglePause: () => Promise; cancelPackage: (packageId: string) => Promise; renamePackage: (packageId: string, newName: string) => Promise; reorderPackages: (packageIds: string[]) => Promise; removeItem: (itemId: string) => Promise; togglePackage: (packageId: string) => Promise; exportPackageSelection: (packageIds: string[]) => Promise<{ saved: boolean; packageCount: number; linkCount: number; filePath?: string }>; exportItemSelection: (itemIds: string[]) => Promise<{ saved: boolean; packageCount: number; linkCount: number; filePath?: string }>; exportQueue: () => Promise<{ saved: boolean }>; importQueue: (json: string) => Promise<{ addedPackages: number; addedLinks: number }>; toggleClipboard: () => Promise; writeClipboardText: (text: string) => Promise; pickFolder: () => Promise; pickContainers: () => Promise; getSessionStats: () => Promise; resetSessionStats: () => Promise; resetDownloadStats: () => Promise; restart: () => Promise; quit: () => Promise; exportBackup: (passphrase: string) => Promise<{ saved: boolean }>; selectBackupImport: () => Promise<{ selected: boolean; requiresPassphrase: boolean; message?: string }>; importBackup: (passphrase?: string) => Promise<{ restored: boolean; relaunch: boolean; message: string }>; cancelBackupImport: () => Promise; exportOnlineBackup: () => Promise<{ key: string }>; importOnlineBackup: (key: string) => Promise<{ restored: boolean; relaunch: false; message: string }>; exportSupportBundle: () => Promise<{ saved: boolean; filePath?: string }>; openLog: () => Promise; openLogDirectory: () => Promise; openAuditLog: () => Promise; openRenameLog: () => Promise; openSessionLog: () => Promise; openTraceLog: () => Promise; openPackageLog: (packageId: string) => Promise; openItemLog: (itemId: string) => Promise; getDebugSetupCheck: () => Promise; getRecentErrors: () => Promise>; testNotification: (url: string, mention: string) => Promise; getTraceConfig: () => Promise; setTraceEnabled: (enabled: boolean, note?: string, durationMinutes?: number) => Promise; rotateDebugToken: () => Promise<{ path: string }>; getRemoteDiagnostics: () => Promise; enableRemoteDiagnostics: (input: EnableRemoteDiagnosticsInput) => Promise; disableRemoteDiagnostics: () => Promise; rotateRemoteDiagnosticsToken: () => Promise; openRealDebridLogin: (request?: RealDebridLoginRequest) => Promise; openAllDebridLogin: () => Promise; importBestDebridCookies: () => Promise; getAllDebridHostInfo: () => Promise; getDebridLinkHostLimits: () => Promise; checkDebridAccounts: (scope?: AccountCheckScope) => Promise; checkAccountCredentials: (input: AccountCredentialCheckInput) => Promise; revealAccountSecret: (input: AccountSecretRequest) => Promise; getArchivePasswordList: () => Promise; retryExtraction: (packageId: string) => Promise; extractNow: (packageId: string) => Promise; resetPackage: (packageId: string) => Promise; getHistory: () => Promise; onHistoryEntryAdded: (callback: (entry: HistoryEntry) => void) => () => void; clearHistory: () => Promise; removeHistoryEntry: (entryId: string) => Promise; removeHistoryEntries: (entryIds: string[]) => Promise; revealHistoryEntry: (entryId: string) => Promise; setPackagePriority: (packageId: string, priority: PackagePriority) => Promise; skipItems: (itemIds: string[]) => Promise; resetItems: (itemIds: string[]) => Promise; startItems: (itemIds: string[]) => Promise; reportRendererError: (report: RendererErrorReport) => void; onStateUpdate: (callback: (snapshot: UiSnapshot) => void) => () => void; onClipboardDetected: (callback: (links: string[]) => void) => () => void; onUpdateInstallProgress: (callback: (progress: UpdateInstallProgress) => void) => () => void; }