import type { DaoCoreConfig } from "../../config/types.daocore.js";
import type { DmPolicy } from "../../config/types.js";
import type { RuntimeEnv } from "../../runtime.js";
import type { WizardPrompter } from "../../wizard/prompts.js";
import type { ChannelAccessPolicy } from "./setup-group-access.js";
import type { ChannelConfigAdapter, ChannelSetupAdapter } from "./types.adapters.js";
import type { ChannelCapabilities, ChannelId, ChannelMeta, ChannelSetupInput } from "./types.core.js";
export type ChannelSetupPlugin = {
    id: ChannelId;
    meta: ChannelMeta;
    capabilities: ChannelCapabilities;
    config: ChannelConfigAdapter<unknown>;
    setup?: ChannelSetupAdapter;
    setupWizard?: ChannelSetupWizard | ChannelSetupWizardAdapter;
};
export type ChannelSetupWizardStatus = {
    configuredLabel: string;
    unconfiguredLabel: string;
    configuredHint?: string;
    unconfiguredHint?: string;
    configuredScore?: number;
    unconfiguredScore?: number;
    resolveConfigured: (params: {
        cfg: DaoCoreConfig;
        accountId?: string;
    }) => boolean | Promise<boolean>;
    resolveStatusLines?: (params: {
        cfg: DaoCoreConfig;
        accountId?: string;
        configured: boolean;
    }) => string[] | Promise<string[]>;
    resolveSelectionHint?: (params: {
        cfg: DaoCoreConfig;
        accountId?: string;
        configured: boolean;
    }) => string | undefined | Promise<string | undefined>;
    resolveQuickstartScore?: (params: {
        cfg: DaoCoreConfig;
        accountId?: string;
        configured: boolean;
    }) => number | undefined | Promise<number | undefined>;
};
export type ChannelSetupWizardCredentialState = {
    accountConfigured: boolean;
    hasConfiguredValue: boolean;
    resolvedValue?: string;
    envValue?: string;
};
export type ChannelSetupWizardCredentialValues = Partial<Record<string, string>>;
export type ChannelSetupWizardNote = {
    title: string;
    lines: string[];
    shouldShow?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
    }) => boolean | Promise<boolean>;
};
export type ChannelSetupWizardEnvShortcut = {
    prompt: string;
    preferredEnvVar?: string;
    isAvailable: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
    }) => boolean;
    apply: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
    }) => DaoCoreConfig | Promise<DaoCoreConfig>;
};
export type ChannelSetupWizardCredential = {
    inputKey: keyof ChannelSetupInput;
    providerHint: string;
    credentialLabel: string;
    preferredEnvVar?: string;
    helpTitle?: string;
    helpLines?: string[];
    envPrompt: string;
    keepPrompt: string;
    inputPrompt: string;
    allowEnv?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
    }) => boolean;
    inspect: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
    }) => ChannelSetupWizardCredentialState;
    shouldPrompt?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
        currentValue?: string;
        state: ChannelSetupWizardCredentialState;
    }) => boolean | Promise<boolean>;
    applyUseEnv?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
    }) => DaoCoreConfig | Promise<DaoCoreConfig>;
    applySet?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
        value: unknown;
        resolvedValue: string;
    }) => DaoCoreConfig | Promise<DaoCoreConfig>;
};
export type ChannelSetupWizardTextInput = {
    inputKey: keyof ChannelSetupInput;
    message: string;
    placeholder?: string;
    required?: boolean;
    applyEmptyValue?: boolean;
    helpTitle?: string;
    helpLines?: string[];
    confirmCurrentValue?: boolean;
    keepPrompt?: string | ((value: string) => string);
    currentValue?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
    }) => string | undefined | Promise<string | undefined>;
    initialValue?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
    }) => string | undefined | Promise<string | undefined>;
    shouldPrompt?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
        currentValue?: string;
    }) => boolean | Promise<boolean>;
    applyCurrentValue?: boolean;
    validate?: (params: {
        value: string;
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
    }) => string | undefined;
    normalizeValue?: (params: {
        value: string;
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
    }) => string;
    applySet?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        value: string;
    }) => DaoCoreConfig | Promise<DaoCoreConfig>;
};
export type ChannelSetupWizardAllowFromEntry = {
    input: string;
    resolved: boolean;
    id: string | null;
};
export type ChannelSetupWizardAllowFrom = {
    helpTitle?: string;
    helpLines?: string[];
    credentialInputKey?: keyof ChannelSetupInput;
    message: string;
    placeholder: string;
    invalidWithoutCredentialNote: string;
    parseInputs?: (raw: string) => string[];
    parseId: (raw: string) => string | null;
    resolveEntries: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
        entries: string[];
    }) => Promise<ChannelSetupWizardAllowFromEntry[]>;
    apply: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        allowFrom: string[];
    }) => DaoCoreConfig | Promise<DaoCoreConfig>;
};
export type ChannelSetupWizardGroupAccess = {
    label: string;
    placeholder: string;
    helpTitle?: string;
    helpLines?: string[];
    skipAllowlistEntries?: boolean;
    currentPolicy: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
    }) => ChannelAccessPolicy;
    currentEntries: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
    }) => string[];
    updatePrompt: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
    }) => boolean;
    setPolicy: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        policy: ChannelAccessPolicy;
    }) => DaoCoreConfig;
    resolveAllowlist?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        credentialValues: ChannelSetupWizardCredentialValues;
        entries: string[];
        prompter: Pick<WizardPrompter, "note">;
    }) => Promise<unknown>;
    applyAllowlist?: (params: {
        cfg: DaoCoreConfig;
        accountId: string;
        resolved: unknown;
    }) => DaoCoreConfig;
};
export type ChannelSetupWizardPrepare = (params: {
    cfg: DaoCoreConfig;
    accountId: string;
    credentialValues: ChannelSetupWizardCredentialValues;
    runtime: ChannelSetupConfigureContext["runtime"];
    prompter: WizardPrompter;
    options?: ChannelSetupConfigureContext["options"];
}) => {
    cfg?: DaoCoreConfig;
    credentialValues?: ChannelSetupWizardCredentialValues;
} | void | Promise<{
    cfg?: DaoCoreConfig;
    credentialValues?: ChannelSetupWizardCredentialValues;
} | void>;
export type ChannelSetupWizardFinalize = (params: {
    cfg: DaoCoreConfig;
    accountId: string;
    credentialValues: ChannelSetupWizardCredentialValues;
    runtime: ChannelSetupConfigureContext["runtime"];
    prompter: WizardPrompter;
    options?: ChannelSetupConfigureContext["options"];
    forceAllowFrom: boolean;
}) => {
    cfg?: DaoCoreConfig;
    credentialValues?: ChannelSetupWizardCredentialValues;
} | void | Promise<{
    cfg?: DaoCoreConfig;
    credentialValues?: ChannelSetupWizardCredentialValues;
} | void>;
export type ChannelSetupWizard = {
    channel: string;
    status: ChannelSetupWizardStatus;
    introNote?: ChannelSetupWizardNote;
    envShortcut?: ChannelSetupWizardEnvShortcut;
    resolveAccountIdForConfigure?: (params: {
        cfg: DaoCoreConfig;
        prompter: WizardPrompter;
        options?: ChannelSetupConfigureContext["options"];
        accountOverride?: string;
        shouldPromptAccountIds: boolean;
        listAccountIds: ChannelSetupPlugin["config"]["listAccountIds"];
        defaultAccountId: string;
    }) => string | Promise<string>;
    resolveShouldPromptAccountIds?: (params: {
        cfg: DaoCoreConfig;
        options?: ChannelSetupConfigureContext["options"];
        shouldPromptAccountIds: boolean;
    }) => boolean;
    prepare?: ChannelSetupWizardPrepare;
    stepOrder?: "credentials-first" | "text-first";
    credentials: ChannelSetupWizardCredential[];
    textInputs?: ChannelSetupWizardTextInput[];
    finalize?: ChannelSetupWizardFinalize;
    completionNote?: ChannelSetupWizardNote;
    dmPolicy?: ChannelSetupDmPolicy;
    allowFrom?: ChannelSetupWizardAllowFrom;
    groupAccess?: ChannelSetupWizardGroupAccess;
    disable?: (cfg: DaoCoreConfig) => DaoCoreConfig;
    onAccountRecorded?: ChannelSetupWizardAdapter["onAccountRecorded"];
};
export type SetupChannelsOptions = {
    allowDisable?: boolean;
    allowSignalInstall?: boolean;
    onSelection?: (selection: ChannelId[]) => void;
    onPostWriteHook?: (hook: ChannelOnboardingPostWriteHook) => void;
    accountIds?: Partial<Record<ChannelId, string>>;
    onAccountId?: (channel: ChannelId, accountId: string) => void;
    onResolvedPlugin?: (channel: ChannelId, plugin: ChannelSetupPlugin) => void;
    promptAccountIds?: boolean;
    forceAllowFromChannels?: ChannelId[];
    deferStatusUntilSelection?: boolean;
    skipStatusNote?: boolean;
    skipDmPolicyPrompt?: boolean;
    skipConfirm?: boolean;
    quickstartDefaults?: boolean;
    initialSelection?: ChannelId[];
    secretInputMode?: "plaintext" | "ref";
};
export type PromptAccountIdParams = {
    cfg: DaoCoreConfig;
    prompter: WizardPrompter;
    label: string;
    currentId?: string;
    listAccountIds: (cfg: DaoCoreConfig) => string[];
    defaultAccountId: string;
};
export type PromptAccountId = (params: PromptAccountIdParams) => Promise<string>;
export type ChannelSetupStatus = {
    channel: ChannelId;
    configured: boolean;
    statusLines: string[];
    selectionHint?: string;
    quickstartScore?: number;
};
export type ChannelSetupStatusContext = {
    cfg: DaoCoreConfig;
    options?: SetupChannelsOptions;
    accountOverrides: Partial<Record<ChannelId, string>>;
};
export type ChannelSetupConfigureContext = {
    cfg: DaoCoreConfig;
    runtime: RuntimeEnv;
    prompter: WizardPrompter;
    options?: SetupChannelsOptions;
    accountOverrides: Partial<Record<ChannelId, string>>;
    shouldPromptAccountIds: boolean;
    forceAllowFrom: boolean;
};
export type ChannelOnboardingPostWriteContext = {
    previousCfg: DaoCoreConfig;
    cfg: DaoCoreConfig;
    accountId: string;
    runtime: RuntimeEnv;
};
export type ChannelOnboardingPostWriteHook = {
    channel: ChannelId;
    accountId: string;
    run: (ctx: {
        cfg: DaoCoreConfig;
        runtime: RuntimeEnv;
    }) => Promise<void> | void;
};
export type ChannelSetupResult = {
    cfg: DaoCoreConfig;
    accountId?: string;
};
export type ChannelSetupConfiguredResult = ChannelSetupResult | "skip";
export type ChannelSetupInteractiveContext = ChannelSetupConfigureContext & {
    configured: boolean;
    label: string;
};
export type ChannelSetupDmPolicy = {
    label: string;
    channel: ChannelId;
    policyKey: string;
    allowFromKey: string;
    resolveConfigKeys?: (cfg: DaoCoreConfig, accountId?: string) => {
        policyKey: string;
        allowFromKey: string;
    };
    getCurrent: (cfg: DaoCoreConfig, accountId?: string) => DmPolicy;
    setPolicy: (cfg: DaoCoreConfig, policy: DmPolicy, accountId?: string) => DaoCoreConfig;
    promptAllowFrom?: (params: {
        cfg: DaoCoreConfig;
        prompter: WizardPrompter;
        accountId?: string;
    }) => Promise<DaoCoreConfig>;
};
export type ChannelSetupWizardAdapter = {
    channel: ChannelId;
    getStatus: (ctx: ChannelSetupStatusContext) => Promise<ChannelSetupStatus>;
    configure: (ctx: ChannelSetupConfigureContext) => Promise<ChannelSetupResult>;
    configureInteractive?: (ctx: ChannelSetupInteractiveContext) => Promise<ChannelSetupConfiguredResult>;
    configureWhenConfigured?: (ctx: ChannelSetupInteractiveContext) => Promise<ChannelSetupConfiguredResult>;
    afterConfigWritten?: (ctx: ChannelOnboardingPostWriteContext) => Promise<void> | void;
    dmPolicy?: ChannelSetupDmPolicy;
    onAccountRecorded?: (accountId: string, options?: SetupChannelsOptions) => void;
    disable?: (cfg: DaoCoreConfig) => DaoCoreConfig;
};
