import type { AndroidOnboardingProgress } from '../android/types.js';
import type { AndroidEffectDeps } from '../android/flow.js';
import type { OnboardingProgress } from '../types.js';
import type { NextStepResult, Platform } from './contract.js';
import type { BuildOutputRecord } from '../../output-record.js';
import { androidViewForStep } from '../android/flow.js';
import { beginOAuthSession, clearOAuthSession, pollOAuthSession } from './oauth-session.js';
/** Facts gathered during preflight; the pure deciders branch only on these. */
export interface PreflightFacts {
    capacitorProject: boolean;
    appId?: string;
    platformsDetected: Platform[];
    authenticated: boolean;
    appRegistered: boolean;
    androidProgress: AndroidOnboardingProgress | null;
    iosProgress: OnboardingProgress | null;
}
/** User input carried into the flow via next_step. */
interface OnboardingInput {
    platform?: string;
    serviceAccountJsonPath?: string;
    runBuild?: boolean;
    checkBuild?: boolean;
    keyId?: string;
    issuerId?: string;
    p8Path?: string;
    serviceAccountMethod?: 'generate' | 'existing';
    playDeveloperId?: string;
    gcpProjectId?: string;
    gcpProjectName?: string;
    androidPackage?: string;
    saMethodChoice?: 'retry' | 'save-anyway' | 'oauth';
    credentialsExistChoice?: 'backup' | 'cancel';
    keystoreMethod?: 'existing' | 'generate';
    keystorePath?: string;
    keystoreStorePassword?: string;
    keystoreAlias?: string;
    keystoreKeyPassword?: string;
    keystoreNewAlias?: string;
    keystorePasswordMethod?: 'random' | 'manual';
    keystoreCommonName?: string;
}
/** Decide the first/again step for a fresh or resumed session. */
export declare function decideStart(facts: PreflightFacts, progress: OnboardingProgress | null, deps: EngineDeps): Promise<NextStepResult>;
export declare function decideIos(facts: PreflightFacts): NextStepResult;
export declare function mapAndroidView(view: ReturnType<typeof androidViewForStep>, facts: PreflightFacts, opts?: {
    keystorePath?: string;
    keystorePassword?: string;
}): NextStepResult;
export declare function decideAndroid(facts: PreflightFacts, deps: EngineDeps, opts?: {
    signInProceed?: boolean;
}): Promise<NextStepResult>;
export declare function decideAdvance(facts: PreflightFacts, progress: OnboardingProgress | null, input: OnboardingInput | undefined, deps: EngineDeps): Promise<NextStepResult>;
export interface EngineDeps {
    cwd: string;
    hasSavedKey: () => boolean;
    getAppId: () => Promise<string | undefined>;
    detectPlatforms: () => Promise<Platform[]>;
    isAppRegistered: (appId: string) => Promise<boolean>;
    loadProgress: (appId: string) => Promise<OnboardingProgress | null>;
    registerApp: (appId: string) => Promise<{
        ok: true;
    } | {
        ok: false;
        alreadyExists: boolean;
        error: string;
    }>;
    loadAndroidProgress: (appId: string) => Promise<AndroidOnboardingProgress | null>;
    finalizeAndroidCredentials: (appId: string) => Promise<{
        ok: true;
    } | {
        ok: false;
        error: string;
    }>;
    readBuildRecord: (path: string) => Promise<BuildOutputRecord | null>;
    buildRecordPath: (appId: string, platform: Platform) => string;
    setIosApiKey: (appId: string, keyId: string, issuerId: string, p8Path: string) => Promise<void>;
    finalizeIosCredentials: (appId: string) => Promise<{
        ok: true;
    } | {
        ok: false;
        error: string;
    }>;
    androidEffectDeps: AndroidEffectDeps;
    /** Returns true when the current host can launch Terminal.app (macOS). Injectable for tests. */
    canLaunchTerminal: () => boolean;
    /** Launch `command` in a new macOS Terminal.app window. Injectable for tests. */
    launchBuildInTerminal: (command: string) => Promise<{
        ok: true;
    } | {
        ok: false;
        error: string;
    }>;
    /**
     * Optional injectable OAuth session registry for testing. When provided, the
     * engine uses these instead of the module-level functions in oauth-session.ts.
     * Production builds omit this and rely on the module-level registry.
     */
    oauthSession?: {
        begin: typeof beginOAuthSession;
        poll: typeof pollOAuthSession;
        clear: typeof clearOAuthSession;
    };
    /**
     * Write the generated/loaded Android keystore (.p12) to a file on disk so the
     * user has a durable copy after onboarding. Called once when the keystore phase
     * completes. Returns the absolute path of the written file.
     *
     * Optional — when omitted the keystore is kept in progress only (no file written).
     * Omitting does not break the flow; the keystore data is always in _keystoreBase64.
     */
    writeKeystoreFile?: (appId: string, base64: string, alias: string) => Promise<string>;
}
export declare function gatherFacts(deps: EngineDeps): Promise<PreflightFacts>;
export declare function runStart(deps: EngineDeps): Promise<NextStepResult>;
export declare function runAdvance(deps: EngineDeps, input?: OnboardingInput): Promise<NextStepResult>;
/**
 * Read-only: determine the onboarding state the user is currently on, WITHOUT
 * running any side effect. Mirrors the branch selection of decideStart/decideAndroid
 * (preflight → platform → android resume step) but never calls effects.
 */
export declare function resolveCurrentState(facts: PreflightFacts): string;
/**
 * Read-only "explain the current step" entry point backing the
 * capgo_builder_onboarding_explain tool. Gathers facts (read-only) and returns a
 * plain-language explanation string. Never advances the flow or runs effects.
 */
export declare function explainOnboarding(deps: EngineDeps, input?: {
    state?: string;
}): Promise<string>;
export {};
