export type ContractResultState = 'accepted' | 'completed' | 'created' | 'empty' | 'partial' | 'queued';
export type ContractProblemCategory = 'auth' | 'conflict' | 'dependency' | 'internal' | 'integration' | 'job' | 'not_found' | 'payment' | 'policy' | 'rate_limit' | 'timeout' | 'validation' | 'workflow';
export type ContractProblemSeverity = 'error' | 'fatal' | 'info' | 'warning';
export type StandardSuccessCode = 'ACCEPTED' | 'CREATED' | 'MULTI_STATUS' | 'NO_CONTENT' | 'OK' | 'PARTIAL' | 'QUEUED';
export type StandardFailureCode = 'BAD_GATEWAY' | 'BAD_REQUEST' | 'CONFLICT' | 'FORBIDDEN' | 'GONE' | 'INTERNAL_ERROR' | 'METHOD_NOT_ALLOWED' | 'NOT_FOUND' | 'NOT_IMPLEMENTED' | 'PAYMENT_REQUIRED' | 'PRECONDITION_FAILED' | 'RATE_LIMITED' | 'SERVICE_UNAVAILABLE' | 'TIMEOUT' | 'UNAUTHENTICATED' | 'VALIDATION_FAILED';
export interface ContractProblemIssue {
    path?: string;
    code?: string;
    message: string;
}
export interface ContractProblemSource {
    service?: string;
    channel?: string;
    workflowId?: string;
    stepId?: string;
    jobId?: string;
    runId?: string;
}
export interface ContractProblemOperation {
    key: string;
    version: string;
    kind?: string;
}
export interface ContractProblem<TCode extends string = StandardFailureCode, TArgs extends Record<string, unknown> = Record<string, unknown>> {
    type: string;
    title: string;
    status: number;
    code: TCode;
    detail?: string;
    instance?: string;
    category: ContractProblemCategory;
    severity: ContractProblemSeverity;
    retryable: boolean;
    retryAfter?: number | Date;
    gqlCode?: string;
    traceId?: string;
    operation?: ContractProblemOperation;
    source?: ContractProblemSource;
    args?: TArgs;
    issues?: ContractProblemIssue[];
    metadata?: Record<string, unknown>;
}
export interface ContractSuccess<TData = unknown, TCode extends string = StandardSuccessCode> {
    ok: true;
    code: TCode;
    status: number;
    data: TData;
    state?: ContractResultState;
    message?: string;
    warnings?: ContractProblem[];
    partialProblems?: ContractProblem[];
    traceId?: string;
    headers?: Record<string, string>;
    links?: Record<string, string>;
    pagination?: Record<string, unknown>;
    cache?: Record<string, unknown>;
    idempotency?: Record<string, unknown>;
    source?: ContractProblemSource;
    metadata?: Record<string, unknown>;
}
export interface ContractFailure<TCode extends string = StandardFailureCode, TArgs extends Record<string, unknown> = Record<string, unknown>> {
    ok: false;
    code: TCode;
    status: number;
    problem: ContractProblem<TCode, TArgs>;
}
export type ContractResult<TData = unknown, TSuccessCode extends string = StandardSuccessCode, TFailureCode extends string = StandardFailureCode, TFailureArgs extends Record<string, unknown> = Record<string, unknown>> = ContractSuccess<TData, TSuccessCode> | ContractFailure<TFailureCode, TFailureArgs>;
export interface ContractSuccessSpec {
    status: number;
    state?: ContractResultState;
    description?: string;
    headers?: Record<string, string>;
}
export interface ContractFailureSpec<TArgs extends Record<string, unknown> = Record<string, unknown>> {
    status?: number;
    description: string;
    title?: string;
    type?: string;
    category?: ContractProblemCategory;
    severity?: ContractProblemSeverity;
    retryable?: boolean;
    retryAfter?: number;
    gqlCode?: string;
    http?: number;
    when?: string;
    args?: TArgs;
}
export interface ResultCatalog<TSuccess extends Record<string, ContractSuccessSpec> = Record<string, ContractSuccessSpec>, TFailure extends Record<string, ContractFailureSpec> = Record<string, ContractFailureSpec>> {
    success?: TSuccess;
    errors?: TFailure;
}
export interface ResultContext {
    traceId?: string;
    operation?: ContractProblemOperation;
    source?: ContractProblemSource;
    metadata?: Record<string, unknown>;
}
export interface ContractSuccessOptions<TCode extends string> {
    code?: TCode;
    status?: number;
    state?: ContractResultState;
    message?: string;
    warnings?: ContractProblem[];
    partialProblems?: ContractProblem[];
    traceId?: string;
    headers?: Record<string, string>;
    links?: Record<string, string>;
    pagination?: Record<string, unknown>;
    cache?: Record<string, unknown>;
    idempotency?: Record<string, unknown>;
    source?: ContractProblemSource;
    metadata?: Record<string, unknown>;
}
export interface ContractFailureOptions<TCode extends string, TArgs extends Record<string, unknown>> extends ResultContext {
    code?: TCode;
    status?: number;
    title?: string;
    detail?: string;
    type?: string;
    category?: ContractProblemCategory;
    severity?: ContractProblemSeverity;
    retryable?: boolean;
    retryAfter?: number | Date;
    gqlCode?: string;
    instance?: string;
    args?: TArgs;
    issues?: ContractProblemIssue[];
}
export declare class ContractSpecError<TCode extends string = StandardFailureCode, TArgs extends Record<string, unknown> = Record<string, unknown>> extends Error {
    readonly problem: ContractProblem<TCode, TArgs>;
    readonly code: TCode;
    readonly status: number;
    readonly retryable: boolean;
    constructor(problem: ContractProblem<TCode, TArgs>);
}
export declare const STANDARD_SUCCESS_SPECS: {
    readonly OK: ContractSuccessSpec;
    readonly CREATED: ContractSuccessSpec;
    readonly ACCEPTED: ContractSuccessSpec;
    readonly NO_CONTENT: ContractSuccessSpec;
    readonly PARTIAL: ContractSuccessSpec;
    readonly MULTI_STATUS: ContractSuccessSpec;
    readonly QUEUED: ContractSuccessSpec;
};
export declare const STANDARD_FAILURE_SPECS: {
    readonly BAD_REQUEST: ContractFailureSpec<Record<string, unknown>>;
    readonly UNAUTHENTICATED: ContractFailureSpec<Record<string, unknown>>;
    readonly PAYMENT_REQUIRED: ContractFailureSpec<Record<string, unknown>>;
    readonly FORBIDDEN: ContractFailureSpec<Record<string, unknown>>;
    readonly NOT_FOUND: ContractFailureSpec<Record<string, unknown>>;
    readonly METHOD_NOT_ALLOWED: ContractFailureSpec<Record<string, unknown>>;
    readonly CONFLICT: ContractFailureSpec<Record<string, unknown>>;
    readonly GONE: ContractFailureSpec<Record<string, unknown>>;
    readonly PRECONDITION_FAILED: ContractFailureSpec<Record<string, unknown>>;
    readonly VALIDATION_FAILED: ContractFailureSpec<Record<string, unknown>>;
    readonly RATE_LIMITED: ContractFailureSpec<Record<string, unknown>>;
    readonly INTERNAL_ERROR: ContractFailureSpec<Record<string, unknown>>;
    readonly NOT_IMPLEMENTED: ContractFailureSpec<Record<string, unknown>>;
    readonly BAD_GATEWAY: ContractFailureSpec<Record<string, unknown>>;
    readonly SERVICE_UNAVAILABLE: ContractFailureSpec<Record<string, unknown>>;
    readonly TIMEOUT: ContractFailureSpec<Record<string, unknown>>;
};
export declare const standardSuccess: {
    pick<const TCodes extends readonly StandardSuccessCode[]>(...codes: TCodes): Pick<{
        readonly OK: ContractSuccessSpec;
        readonly CREATED: ContractSuccessSpec;
        readonly ACCEPTED: ContractSuccessSpec;
        readonly NO_CONTENT: ContractSuccessSpec;
        readonly PARTIAL: ContractSuccessSpec;
        readonly MULTI_STATUS: ContractSuccessSpec;
        readonly QUEUED: ContractSuccessSpec;
    }, StandardSuccessCode>;
    OK: ContractSuccessSpec;
    CREATED: ContractSuccessSpec;
    ACCEPTED: ContractSuccessSpec;
    NO_CONTENT: ContractSuccessSpec;
    PARTIAL: ContractSuccessSpec;
    MULTI_STATUS: ContractSuccessSpec;
    QUEUED: ContractSuccessSpec;
};
export declare const standardErrors: {
    pick<const TCodes extends readonly StandardFailureCode[]>(...codes: TCodes): Pick<{
        readonly BAD_REQUEST: ContractFailureSpec<Record<string, unknown>>;
        readonly UNAUTHENTICATED: ContractFailureSpec<Record<string, unknown>>;
        readonly PAYMENT_REQUIRED: ContractFailureSpec<Record<string, unknown>>;
        readonly FORBIDDEN: ContractFailureSpec<Record<string, unknown>>;
        readonly NOT_FOUND: ContractFailureSpec<Record<string, unknown>>;
        readonly METHOD_NOT_ALLOWED: ContractFailureSpec<Record<string, unknown>>;
        readonly CONFLICT: ContractFailureSpec<Record<string, unknown>>;
        readonly GONE: ContractFailureSpec<Record<string, unknown>>;
        readonly PRECONDITION_FAILED: ContractFailureSpec<Record<string, unknown>>;
        readonly VALIDATION_FAILED: ContractFailureSpec<Record<string, unknown>>;
        readonly RATE_LIMITED: ContractFailureSpec<Record<string, unknown>>;
        readonly INTERNAL_ERROR: ContractFailureSpec<Record<string, unknown>>;
        readonly NOT_IMPLEMENTED: ContractFailureSpec<Record<string, unknown>>;
        readonly BAD_GATEWAY: ContractFailureSpec<Record<string, unknown>>;
        readonly SERVICE_UNAVAILABLE: ContractFailureSpec<Record<string, unknown>>;
        readonly TIMEOUT: ContractFailureSpec<Record<string, unknown>>;
    }, StandardFailureCode>;
    BAD_REQUEST: ContractFailureSpec<Record<string, unknown>>;
    UNAUTHENTICATED: ContractFailureSpec<Record<string, unknown>>;
    PAYMENT_REQUIRED: ContractFailureSpec<Record<string, unknown>>;
    FORBIDDEN: ContractFailureSpec<Record<string, unknown>>;
    NOT_FOUND: ContractFailureSpec<Record<string, unknown>>;
    METHOD_NOT_ALLOWED: ContractFailureSpec<Record<string, unknown>>;
    CONFLICT: ContractFailureSpec<Record<string, unknown>>;
    GONE: ContractFailureSpec<Record<string, unknown>>;
    PRECONDITION_FAILED: ContractFailureSpec<Record<string, unknown>>;
    VALIDATION_FAILED: ContractFailureSpec<Record<string, unknown>>;
    RATE_LIMITED: ContractFailureSpec<Record<string, unknown>>;
    INTERNAL_ERROR: ContractFailureSpec<Record<string, unknown>>;
    NOT_IMPLEMENTED: ContractFailureSpec<Record<string, unknown>>;
    BAD_GATEWAY: ContractFailureSpec<Record<string, unknown>>;
    SERVICE_UNAVAILABLE: ContractFailureSpec<Record<string, unknown>>;
    TIMEOUT: ContractFailureSpec<Record<string, unknown>>;
};
export declare function isStandardSuccessCode(code: string): code is StandardSuccessCode;
export declare function isStandardFailureCode(code: string): code is StandardFailureCode;
export declare const success: {
    ok: <_TData = unknown>(options?: Partial<ContractSuccessSpec>) => {
        status: number;
        state: ContractResultState;
        description: string;
        headers: Record<string, string> | undefined;
    };
    created: <_TData = unknown>(options?: Partial<ContractSuccessSpec>) => {
        status: number;
        state: ContractResultState;
        description: string;
        headers: Record<string, string> | undefined;
    };
    accepted: <_TData = unknown>(options?: Partial<ContractSuccessSpec>) => {
        status: number;
        state: ContractResultState;
        description: string;
        headers: Record<string, string> | undefined;
    };
    queued: <_TData = unknown>(options?: Partial<ContractSuccessSpec>) => {
        status: number;
        state: ContractResultState;
        description: string;
        headers: Record<string, string> | undefined;
    };
    noContent: (options?: Partial<ContractSuccessSpec>) => {
        status: number;
        state: ContractResultState;
        description: string;
        headers: Record<string, string> | undefined;
    };
    partial: <_TData = unknown>(options?: Partial<ContractSuccessSpec>) => {
        status: number;
        state: ContractResultState;
        description: string;
        headers: Record<string, string> | undefined;
    };
};
export declare const failure: {
    badRequest: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    unauthenticated: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    paymentRequired: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    forbidden: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    notFound: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    conflict: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    validation: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    rateLimited: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    internal: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
    timeout: <TArgs extends Record<string, unknown> = Record<string, unknown>>(options?: Partial<ContractFailureSpec<TArgs>>) => ContractFailureSpec<TArgs>;
};
export declare function defineResultCatalog<TSuccess extends Record<string, ContractSuccessSpec>, TFailure extends Record<string, ContractFailureSpec>>(catalog: ResultCatalog<TSuccess, TFailure>): ResultCatalog<TSuccess, TFailure>;
export declare function contractOk<TData, TCode extends string = 'OK'>(data: TData, options?: ContractSuccessOptions<TCode>): ContractSuccess<TData, TCode>;
export declare function contractCreated<TData, TCode extends string = 'CREATED'>(data: TData, options?: Omit<ContractSuccessOptions<TCode>, 'state' | 'status'> & {
    status?: number;
}): ContractSuccess<TData, TCode>;
export declare function contractAccepted<TData, TCode extends string = 'ACCEPTED'>(data: TData, options?: Omit<ContractSuccessOptions<TCode>, 'state' | 'status'> & {
    status?: number;
}): ContractSuccess<TData, TCode>;
export declare function contractQueued<TData, TCode extends string = 'QUEUED'>(data: TData, options?: Omit<ContractSuccessOptions<TCode>, 'state' | 'status'> & {
    status?: number;
}): ContractSuccess<TData, TCode>;
export declare function contractNoContent<TCode extends string = 'NO_CONTENT'>(options?: Omit<ContractSuccessOptions<TCode>, 'state' | 'status'> & {
    status?: number;
}): ContractSuccess<undefined, TCode>;
export declare function contractPartial<TData, TCode extends string = 'PARTIAL'>(data: TData, options?: Omit<ContractSuccessOptions<TCode>, 'state' | 'status'> & {
    status?: number;
    partialProblems?: ContractProblem[];
}): ContractSuccess<TData, TCode>;
export declare function contractFail<TCode extends string = StandardFailureCode, TArgs extends Record<string, unknown> = Record<string, unknown>>(code: TCode, args?: TArgs, options?: Omit<ContractFailureOptions<TCode, TArgs>, 'code' | 'args'>): ContractFailure<TCode, TArgs>;
export declare function contractValidationFail(issues: ContractProblemIssue[], options?: Omit<ContractFailureOptions<'VALIDATION_FAILED', Record<string, unknown>>, 'code' | 'issues'>): ContractFailure<'VALIDATION_FAILED'>;
export declare function createContractError<TCode extends string = StandardFailureCode, TArgs extends Record<string, unknown> = Record<string, unknown>>(code: TCode, args?: TArgs, options?: Omit<ContractFailureOptions<TCode, TArgs>, 'code' | 'args'>): ContractSpecError<TCode, TArgs>;
export declare function isContractProblem(value: unknown): value is ContractProblem;
export declare function isContractSuccess(value: unknown): value is ContractSuccess;
export declare function isContractFailure(value: unknown): value is ContractFailure;
export declare function isContractResult(value: unknown): value is ContractResult;
export declare function isContractSpecError(value: unknown): value is ContractSpecError;
export declare function normalizeContractResult<TData>(value: TData | ContractResult<TData>, options?: ContractSuccessOptions<StandardSuccessCode>): ContractResult<TData>;
export declare function normalizeContractError(error: unknown, options?: ResultContext & {
    defaultCode?: StandardFailureCode;
    status?: number;
    category?: ContractProblemCategory;
    declaredErrors?: Record<string, ContractFailureSpec>;
}): ContractFailure<string, Record<string, unknown>>;
export declare function problemToSafeMessage(problem: ContractProblem<string, Record<string, unknown>>): string;
