import type { ComponentManifest, ConfigVarResultCollection, CustomerAttributes, DataSourceResultType, DataSourceType, DebugContext, ExecutionFrame, FlowAttributes, FlowInvoker, FlowSchemas, Inputs, InstanceAttributes, IntegrationAttributes, PollingTriggerPerformFunction, TriggerEventFunctionReturn, TriggerPerformFunction, TriggerResult as TriggerPerformResult, UserAttributes } from "../types";
import type { CNIPollingPerformFunction, ComponentRefTriggerPerformFunction } from "./triggerTypes";
interface DisplayDefinition {
    label: string;
    description: string;
}
export { CustomerAttributes, FlowAttributes, FlowSchemas, InstanceAttributes, IntegrationAttributes, UserAttributes, } from "../types";
export interface PublishingMetadata {
    flowsWithCustomerRequiredAPIKeys: {
        name: string;
        testApiKeys?: string[];
    }[];
}
export interface Component<TInputs extends Inputs = Inputs, TActionInputs extends Inputs = Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerPerformResult<TAllowsBranching, TPayload> = TriggerPerformResult<TAllowsBranching, TPayload>> {
    key: string;
    public?: boolean;
    documentationUrl?: string;
    display: DisplayDefinition & {
        category?: string;
        iconPath?: string;
    };
    actions: Record<string, Action>;
    triggers: Record<string, Trigger<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult>>;
    dataSources: Record<string, DataSource>;
    connections: Connection[];
    codeNativeIntegrationYAML?: string;
    publishingMetadata?: PublishingMetadata;
}
export interface Action {
    key: string;
    display: DisplayDefinition & {
        directions?: string;
        important?: boolean;
    };
    inputs: Input[];
    terminateExecution?: boolean;
    breakLoop?: boolean;
    allowsBranching?: boolean;
    staticBranchNames?: string[];
    dynamicBranchInput?: string;
    perform: ActionPerformFunction;
    examplePayload?: unknown;
    /**
     * The on-the-wire form of an action's `outputSchema`, as accepted by the
     * `PublishComponent` mutation. JSON Schemas are serialized to strings and the
     * branching variant's per-branch map is flattened to a `{ name, schema }`
     * list (GraphQL input has no map type). Produced by `convertOutputSchema`
     * from the author-facing `OutputSchema`.
     */
    outputSchema?: ServerOutputSchema;
}
export type ServerOutputSchema = {
    type: "actionOutput";
    schema: string;
} | {
    type: "branchingOutput";
    branchSchemas: Array<{
        name: string;
        schema: string;
    }>;
};
export type ActionLoggerFunction = (...args: unknown[]) => void;
export interface ActionLogger {
    metric: ActionLoggerFunction;
    trace: ActionLoggerFunction;
    debug: ActionLoggerFunction;
    info: ActionLoggerFunction;
    log: ActionLoggerFunction;
    warn: ActionLoggerFunction;
    error: ActionLoggerFunction;
}
export type ActionContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TComponentActions extends Record<string, ComponentManifest["actions"]> = Record<string, ComponentManifest["actions"]>, TFlows extends string[] = string[]> = {
    logger: ActionLogger;
    instanceState: Record<string, unknown>;
    crossFlowState: Record<string, unknown>;
    executionState: Record<string, unknown>;
    integrationState: Record<string, unknown>;
    configVars: TConfigVars;
    stepId: string;
    executionId: string;
    webhookUrls: Record<string, string>;
    webhookApiKeys: Record<string, string[]>;
    invokeUrl: string;
    customer: CustomerAttributes;
    instance: InstanceAttributes;
    user: UserAttributes;
    integration: IntegrationAttributes;
    flow: FlowAttributes;
    startedAt: string;
    executionFrame: ExecutionFrame;
    flowSchemas: FlowSchemas;
    globalDebug?: boolean;
    runnerAllocatedMemoryMb?: number;
    components: {
        [K in keyof TComponentActions]: {
            [A in keyof TComponentActions[K]]: TComponentActions[K][A]["perform"];
        };
    };
    invokeFlow: FlowInvoker<TFlows>;
    debug: DebugContext;
};
type TriggerOptionChoice = "invalid" | "valid" | "required";
export interface TriggerPayload {
    headers: Record<string, string>;
    queryParameters: Record<string, string>;
    rawBody: {
        data: unknown;
        contentType?: string;
    };
    body: {
        data: unknown;
        contentType?: string;
    };
    pathFragment: string;
    webhookUrls: Record<string, string>;
    webhookApiKeys: Record<string, string[]>;
    invokeUrl: string;
    executionId: string;
    customer: CustomerAttributes;
    instance: InstanceAttributes;
    user: UserAttributes;
    integration: IntegrationAttributes;
    flow: FlowAttributes;
    startedAt: string;
    globalDebug: boolean;
}
interface HttpResponse {
    statusCode: number;
    contentType: string;
    headers?: Record<string, string>;
    body?: string;
}
interface TriggerBaseResult<TPayload extends TriggerPayload = TriggerPayload> {
    payload: TPayload;
    response?: HttpResponse;
    instanceState?: Record<string, unknown>;
    crossFlowState?: Record<string, unknown>;
    executionState?: Record<string, unknown>;
    integrationState?: Record<string, unknown>;
    failed?: boolean;
    error?: Record<string, unknown>;
}
interface TriggerBranchingResult<TPayload extends TriggerPayload = TriggerPayload> extends TriggerBaseResult<TPayload> {
    branch: string;
}
export type TriggerResult<TPayload extends TriggerPayload = TriggerPayload> = TriggerBranchingResult<TPayload> | TriggerBaseResult<TPayload> | undefined;
export type TriggerEventFunctionResult = TriggerEventFunctionReturn | void;
export type TriggerEventFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<TriggerEventFunctionResult>;
/**
 * Wire format the platform expects for a trigger. Note: function references
 * (perform, resolveTriggerItems, getNextPaginationState, ...) don't survive JSON
 * serialization, so each callback has a paired `hasXxx: boolean` flag the
 * server reads to detect presence. Keep the flag and its callback in sync.
 *
 * The on-deploy fire is named asymmetrically by intent: CNI flow authors set
 * `onDeployTrigger` (sibling to `onTrigger`), component-trigger authors set
 * `onDeployPerform` (sibling to `perform`), and both flatten to
 * `onDeployPerform` here on the wire.
 */
export interface Trigger<TInputs extends Inputs, TActionInputs extends Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerPerformResult<TAllowsBranching, TPayload> = TriggerPerformResult<TAllowsBranching, TPayload>> {
    key: string;
    display: DisplayDefinition & {
        directions?: string;
        important?: boolean;
    };
    inputs: Input[];
    terminateExecution?: boolean;
    breakLoop?: boolean;
    allowsBranching?: boolean;
    staticBranchNames?: string[];
    dynamicBranchInput?: string;
    perform: TriggerPerformFunction<TInputs, TConfigVars, TAllowsBranching, TResult> | PollingTriggerPerformFunction<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult> | CNIPollingPerformFunction<TInputs, TConfigVars, TPayload, TAllowsBranching> | ComponentRefTriggerPerformFunction<TInputs, TConfigVars>;
    onInstanceDeploy?: TriggerEventFunction;
    hasOnInstanceDeploy?: boolean;
    onInstanceDelete?: TriggerEventFunction;
    hasOnInstanceDelete?: boolean;
    webhookLifecycleHandlers?: {
        create: TriggerEventFunction;
        delete: TriggerEventFunction;
    };
    webhookCreate?: TriggerEventFunction;
    hasWebhookCreateFunction?: boolean;
    webhookDelete?: TriggerEventFunction;
    hasWebhookDeleteFunction?: boolean;
    scheduleSupport: TriggerOptionChoice;
    synchronousResponseSupport: TriggerOptionChoice;
    triggerResolverSupport?: TriggerOptionChoice;
    /**
     * The single default batch size shared by the trigger and on-deploy resolvers. The
     * platform reads only this field for both paths; there is no separate on-deploy default.
     */
    triggerResolverDefaultBatchSize?: number;
    triggerResolverDefaultConcurrentBatchLimit?: number;
    resolveTriggerItems?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<TPayload>) => unknown[];
    hasResolveTriggerItems?: boolean;
    getNextPaginationState?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<TPayload>) => Record<string, unknown> | null;
    hasGetNextDiscoveryState?: boolean;
    onDeployPerform?: TriggerPerformFunction<TInputs, TConfigVars, TAllowsBranching, TResult> | PollingTriggerPerformFunction<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult> | CNIPollingPerformFunction<TInputs, TConfigVars, TPayload, TAllowsBranching> | ComponentRefTriggerPerformFunction<TInputs, TConfigVars>;
    hasOnDeployPerform?: boolean;
    resolveOnDeployItems?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<TPayload>) => unknown[];
    hasResolveOnDeployItems?: boolean;
    getOnDeployNextPaginationState?: (context: ActionContext<TConfigVars>, result: TriggerBaseResult<TPayload>) => Record<string, unknown> | null;
    hasGetOnDeployNextDiscoveryState?: boolean;
    examplePayload?: unknown;
    isCommonTrigger?: boolean;
    isPollingTrigger?: boolean;
}
export interface DataSourceContext<TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection> {
    logger: ActionLogger;
    configVars: TConfigVars;
    customer: CustomerAttributes;
    instance: InstanceAttributes;
    user: UserAttributes;
}
export type DataSourceResult = {
    result: DataSourceResultType;
    supplementalData?: {
        data: unknown;
        contentType: string;
    };
};
export type DataSourcePerformFunction = (context: DataSourceContext, params: Record<string, unknown>) => Promise<DataSourceResult>;
export interface DataSource {
    key: string;
    display: DisplayDefinition & {
        directions?: string;
        important?: boolean;
    };
    inputs: Input[];
    perform: DataSourcePerformFunction;
    dataSourceType: DataSourceType;
    examplePayload?: unknown;
}
export declare enum OAuth2Type {
    ClientCredentials = "client_credentials",
    AuthorizationCode = "authorization_code"
}
export interface Connection {
    key: string;
    label: string;
    comments?: string;
    oauth2Type?: OAuth2Type;
    iconPath?: string;
    avatarIconPath?: string;
    inputs: (Input & {
        shown?: boolean;
        onPremControlled?: boolean;
    })[];
}
export interface ConnectionValue {
    key: string;
    configVarKey: string;
    fields: {
        [key: string]: unknown;
    };
    token?: Record<string, unknown>;
    context?: Record<string, unknown>;
}
interface ServerPerformDataStructureReturn {
    data: boolean | number | string | Record<string, unknown> | unknown[] | unknown;
    contentType?: string;
    statusCode?: number;
    headers?: Record<string, string>;
    instanceState?: Record<string, unknown>;
    crossFlowState?: Record<string, unknown>;
    executionState?: Record<string, unknown>;
    integrationState?: Record<string, unknown>;
    failed?: boolean;
    error?: Record<string, unknown>;
}
interface ServerPerformDataReturn {
    data: Buffer | string | unknown;
    contentType: string;
    statusCode?: number;
    headers?: Record<string, string>;
    instanceState?: Record<string, unknown>;
    crossFlowState?: Record<string, unknown>;
    executionState?: Record<string, unknown>;
    integrationState?: Record<string, unknown>;
    failed?: boolean;
    error?: Record<string, unknown>;
}
interface ServerPerformBranchingDataStructureReturn extends ServerPerformDataStructureReturn {
    branch: string;
}
interface ServerPerformBranchingDataReturn extends ServerPerformDataReturn {
    branch: string;
}
export type ActionPerformReturn = ServerPerformDataStructureReturn | ServerPerformBranchingDataStructureReturn | ServerPerformDataReturn | ServerPerformBranchingDataReturn | undefined;
export type ActionPerformFunction = (context: ActionContext, params: Record<string, unknown>) => Promise<ActionPerformReturn>;
interface InputFieldChoice {
    label: string;
    value: string;
}
export interface Input {
    key: string;
    label: string;
    keyLabel?: string;
    type: string;
    collection?: string;
    placeholder?: string;
    default?: unknown;
    comments?: string;
    example?: string;
    required?: boolean;
    model?: InputFieldChoice[];
    language?: string;
    onPremiseControlled?: boolean;
    dataSource?: string;
    shown?: boolean;
    /** Nested children. For `structuredObject`, the declared inputs; for
     * `dynamicObject`, one `structuredObject` per configuration. */
    inputs?: Input[];
}
export * from "./asyncContext";
