import { ImmutableObject } from '@redocly/hookstate-core';
import { JSX } from 'react/jsx-runtime';
import { NamedExoticComponent } from 'react';
import { ReactElement } from 'react';

declare type ApiPath = {
    path: string;
    method: string;
};

export declare function applyThemeToDOM(resolvedTheme: ResolvedTheme): void;

declare type AuthorizationCodeOAuthFlowsObject = {
    authorizationUrl: string;
    tokenUrl: string;
    scopes: Record<string, string>;
    'x-usePkce'?: boolean;
};

declare type Certificate = {
    host: string;
    port: string;
    crtFilePath: string;
    keyFilePath: string;
};

declare type ChangedOperation = {
    apiPath: ApiPath;
    requestValues: {
        cookie?: {
            [key: string]: string;
        };
        header?: {
            [key: string]: string;
        };
        query?: {
            [key: string]: string;
        };
        body?: any;
    };
    activeExampleName?: string;
    activeSecuritySchemeIds?: string[];
    activeOneOf?: {
        [key: string]: number;
    };
};

declare type ClientCredentialsOAuthFlowsObject = {
    'x-assertionType'?: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
    tokenUrl: string;
    scopes: Record<string, string>;
};

declare type ConvertOperationFunction = (path: string, method: string, openAPI: any) => OpenAPIOperation_2 | undefined;

export declare function EmbeddedReplay(props: ReplayAppProps): JSX.Element;

export declare function getCurrentTheme(): ResolvedTheme;

declare type GetOperationURLFunction = (operationId?: string) => string | undefined;

declare type ImplicitOAuthFlowsObject = {
    authorizationUrl?: string;
    scopes: Record<string, string>;
};

declare type InputSettings = {
    corsProxyUrl?: string;
    mockServer?: MockServer;
    disableCollectionsTab?: boolean;
    disableDraft?: boolean;
    oAuth2RedirectURI?: string | null;
    inline?: boolean;
    selectedEnvironment?: string;
    allowedEnvironments?: string[];
    apiId?: string;
    predefinedEnvValues?: Record<string, Record<string, string>>;
    certificates?: Certificate[];
    storageKey?: string;
    convertOperationToReplayValue?: ConvertOperationFunction;
    getOperationUrl?: GetOperationURLFunction;
    onRequestReset?: () => void;
    telemetry?: {
        tracerName?: TracerName;
        collectorUrl?: string;
    };
};

declare type MediaType = {
    name: string;
    examples?: {
        [name: string]: {
            value: any;
            summary?: string | GenericObject;
            description?: string;
        };
    };
    schema?: object;
    parameters: {
        inputType: 'file' | 'text';
        name: string;
        example: string;
    }[];
};

declare type MediaTypes = {
    [name: string]: MediaType;
};

declare type MockServer = {
    url: string;
    position: 'first' | 'last' | 'replace' | 'off';
    description: string;
};

export declare const Modal: NamedExoticComponent<ModalProps>;

declare type ModalProps = {
    isOpen: boolean;
    onClose: () => void;
    title: string;
    hideHeader?: boolean;
    content: ReactElement;
    mountId?: string;
    className?: string;
};

declare type OAuthFlowsObject = {
    implicit?: ImplicitOAuthFlowsObject;
    password?: PasswordOAuthFlowsObject;
    clientCredentials?: ClientCredentialsOAuthFlowsObject;
    authorizationCode?: AuthorizationCodeOAuthFlowsObject;
};

declare interface OpenAPICallback {
    [name: string]: OpenAPIPath;
}

declare interface OpenAPIComponents {
    schemas?: {
        [name: string]: Referenced<OpenAPISchema>;
    };
    responses?: {
        [name: string]: Referenced<OpenAPIResponse>;
    };
    parameters?: {
        [name: string]: Referenced<OpenAPIParameter>;
    };
    examples?: {
        [name: string]: Referenced<OpenAPIExample>;
    };
    requestBodies?: {
        [name: string]: Referenced<OpenAPIRequestBody>;
    };
    headers?: {
        [name: string]: Referenced<OpenAPIHeader>;
    };
    securitySchemes?: {
        [name: string]: Referenced<OpenAPISecurityScheme>;
    };
    links?: {
        [name: string]: Referenced<OpenAPILink>;
    };
    callbacks?: {
        [name: string]: Referenced<OpenAPICallback>;
    };
}

declare interface OpenAPIContact {
    name?: string;
    url?: string;
    email?: string;
}

declare interface OpenAPIDefinition {
    openapi: string;
    info: OpenAPIInfo;
    servers?: OpenAPIServer[];
    paths: OpenAPIPaths;
    components?: OpenAPIComponents;
    security?: OpenAPISecurityRequirement[];
    tags?: OpenAPITag[];
    externalDocs?: OpenAPIExternalDocumentation;
    webhooks?: OpenAPIPaths;
    'x-webhooks'?: OpenAPIPaths;
    'x-tagGroups'?: Array<{
        name: string;
        tags: Array<string>;
    }>;
    'x-feedback'?: any;
}

declare interface OpenAPIDiscriminator {
    propertyName: string;
    mapping?: {
        [name: string]: string;
    };
    'x-explicitMappingOnly'?: boolean;
}

declare interface OpenAPIEncoding {
    contentType: string;
    headers?: {
        [name: string]: Referenced<OpenAPIHeader>;
    };
    style: OpenAPIParameterStyle;
    explode: boolean;
    allowReserved: boolean;
}

declare interface OpenAPIExample extends ParsedDescriptionWithSummary {
    value: any;
    summary?: string;
    description?: string;
    externalValue?: string;
}

declare interface OpenAPIExternalDocumentation extends ParsedDescription {
    description?: string;
    url: string;
}

declare type OpenAPIHeader = Omit<OpenAPIParameter, 'in' | 'name'>;

declare interface OpenAPIInfo extends ParsedDescriptionWithSummary {
    title: string;
    version: string;
    description?: string;
    summary?: string;
    termsOfService?: string;
    contact?: OpenAPIContact;
    license?: OpenAPILicense;
    'x-logo'?: XLogo;
    'x-metadata'?: XMetadata;
    'x-seo'?: XSEO;
}

declare interface OpenAPILicense {
    name: string;
    url?: string;
    identifier?: string;
}

declare interface OpenAPILink {
    $ref?: string;
}

declare interface OpenAPIMediaType {
    schema?: Referenced<OpenAPISchema>;
    example?: any;
    examples?: {
        [name: string]: Referenced<OpenAPIExample>;
    };
    encoding?: {
        [field: string]: OpenAPIEncoding;
    };
}

declare interface OpenAPIOperation extends ParsedDescriptionWithSummary {
    tags?: string[];
    summary?: string;
    description?: string;
    externalDocs?: OpenAPIExternalDocumentation;
    operationId?: string;
    parameters?: Array<Referenced<OpenAPIParameter>>;
    requestBody?: Referenced<OpenAPIRequestBody>;
    responses: OpenAPIResponses;
    callbacks?: {
        [name: string]: Referenced<OpenAPICallback>;
    };
    deprecated?: boolean;
    security?: OpenAPISecurityRequirement[];
    servers?: OpenAPIServer[];
    'x-badges'?: OpenAPIXBadges[];
    'x-hideReplay'?: boolean;
}

declare type OpenAPIOperation_2 = {
    id: string;
    name: string;
    method: string;
    path: string;
    href: string;
    operationId?: string;
    parameters: OperationParameter[];
    body?: {
        mediaTypes: MediaTypes;
        required?: boolean;
        activeExampleName?: string;
    };
    servers: Server[];
    security?: OperationSecurity[][];
    response?: Response_2 | null;
};

declare interface OpenAPIParameter extends ParsedDescription {
    name: string;
    in?: OpenAPIParameterLocation;
    description?: string;
    required?: boolean;
    deprecated?: boolean;
    allowEmptyValue?: boolean;
    style?: OpenAPIParameterStyle;
    explode?: boolean;
    allowReserved?: boolean;
    schema?: Referenced<OpenAPISchema>;
    example?: any;
    examples?: {
        [media: string]: Referenced<OpenAPIExample>;
    };
    content?: {
        [media: string]: OpenAPIMediaType;
    };
    encoding?: Record<string, OpenAPIEncoding>;
    const?: any;
}

declare type OpenAPIParameterLocation = 'query' | 'header' | 'path' | 'cookie';

declare type OpenAPIParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';

declare interface OpenAPIPath extends Partial<OpenAPIRef>, ParsedDescriptionWithSummary {
    summary?: string;
    description?: string;
    get?: OpenAPIOperation;
    put?: OpenAPIOperation;
    post?: OpenAPIOperation;
    delete?: OpenAPIOperation;
    options?: OpenAPIOperation;
    head?: OpenAPIOperation;
    patch?: OpenAPIOperation;
    trace?: OpenAPIOperation;
    servers?: OpenAPIServer[];
    parameters?: Array<Referenced<OpenAPIParameter>>;
}

declare interface OpenAPIPaths {
    [path: string]: OpenAPIPath;
}

declare interface OpenAPIRef extends ParsedDescriptionWithSummary {
    $ref: string;
    'x-refsStack'?: string[];
    summary?: string;
    description?: string;
}

declare interface OpenAPIRequestBody extends ParsedDescription {
    description?: string;
    required?: boolean;
    content?: {
        [mime: string]: OpenAPIMediaType;
    };
    'x-examples'?: {
        [mime: string]: {
            [name: string]: Referenced<OpenAPIExample>;
        };
    };
    'x-example'?: {
        [mime: string]: any;
    };
}

declare interface OpenAPIResponse extends ParsedDescription {
    description?: string;
    headers?: {
        [name: string]: Referenced<OpenAPIHeader>;
    };
    content?: {
        [mime: string]: OpenAPIMediaType;
    };
    links?: {
        [name: string]: Referenced<OpenAPILink>;
    };
    'x-examples'?: {
        [mime: string]: {
            [name: string]: Referenced<OpenAPIExample>;
        };
    };
    'x-example'?: {
        [mime: string]: any;
    };
}

declare interface OpenAPIResponses {
    [code: string]: OpenAPIResponse;
}

declare interface OpenAPISchema extends ParsedDescription {
    $ref?: string;
    type?: string | string[];
    properties?: {
        [name: string]: OpenAPISchema;
    };
    patternProperties?: {
        [name: string]: OpenAPISchema;
    };
    additionalProperties?: boolean | OpenAPISchema;
    unevaluatedProperties?: boolean | OpenAPISchema;
    description?: string;
    default?: any;
    items?: OpenAPISchema | OpenAPISchema[] | boolean;
    required?: string[];
    readOnly?: boolean;
    writeOnly?: boolean;
    deprecated?: boolean;
    format?: string;
    externalDocs?: OpenAPIExternalDocumentation;
    discriminator?: OpenAPIDiscriminator;
    nullable?: boolean;
    oneOf?: OpenAPISchema[];
    anyOf?: OpenAPISchema[];
    allOf?: OpenAPISchema[];
    not?: OpenAPISchema;
    title?: string;
    multipleOf?: number;
    maximum?: number;
    exclusiveMaximum?: boolean | number;
    minimum?: number;
    exclusiveMinimum?: boolean | number;
    maxLength?: number;
    minLength?: number;
    pattern?: string;
    maxItems?: number;
    minItems?: number;
    uniqueItems?: boolean;
    maxProperties?: number;
    minProperties?: number;
    enum?: any[];
    example?: any;
    examples?: any[];
    const?: string;
    contentEncoding?: string;
    contentMediaType?: string;
    if?: OpenAPISchema;
    else?: OpenAPISchema;
    then?: OpenAPISchema;
    prefixItems?: OpenAPISchema[];
    additionalItems?: OpenAPISchema | boolean;
    xml?: XMLObject;
}

declare interface OpenAPISecurityRequirement {
    [name: string]: string[];
}

declare interface OpenAPISecurityScheme extends ParsedDescription {
    type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
    description?: string;
    name?: string;
    in?: 'query' | 'header' | 'cookie';
    scheme?: string;
    bearerFormat: string;
    'x-defaultClientId'?: string;
    flows: {
        implicit?: {
            refreshUrl?: string;
            scopes: Record<string, string>;
            authorizationUrl: string;
            'x-defaultClientId'?: string;
        };
        password?: {
            refreshUrl?: string;
            scopes: Record<string, string>;
            tokenUrl: string;
            'x-defaultClientId'?: string;
        };
        clientCredentials?: {
            refreshUrl?: string;
            scopes: Record<string, string>;
            tokenUrl: string;
            'x-defaultClientId'?: string;
            'x-assertionType'?: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
        };
        authorizationCode?: {
            refreshUrl?: string;
            scopes: Record<string, string>;
            authorizationUrl: string;
            tokenUrl: string;
            'x-defaultClientId'?: string;
        };
    };
    openIdConnectUrl?: string;
}

declare interface OpenAPIServer extends ParsedDescription {
    url: string;
    description?: string;
    variables?: OpenAPIServerVariables;
}

declare interface OpenAPIServerVariable extends ParsedDescription {
    enum?: string[];
    default: string;
    description?: string;
}

declare interface OpenAPIServerVariables {
    [name: string]: OpenAPIServerVariable;
}

declare interface OpenAPITag extends ParsedDescription {
    name: string;
    description?: string;
    externalDocs?: OpenAPIExternalDocumentation;
    'x-displayName'?: string;
    'x-rbac'?: Record<string, unknown>;
}

declare interface OpenAPIXBadges {
    name: string;
    color?: string;
    position?: 'before' | 'after';
}

declare type OperationIn = 'query' | 'header' | 'path' | 'cookie';

declare type OperationParameter = {
    name: string;
    in: OperationIn;
    required: boolean;
    description?: string | {
        raw: string;
        result: any;
    };
    example?: any;
    schema?: OperationParameterSchema;
};

declare type OperationParameterSchema = {
    typePrefix: string;
    title: string;
    displayType: string;
    displayFormat?: string;
    contentEncoding?: string;
    constraints: string[];
    enum?: string[];
};

export declare type OperationSecurity = {
    id: string;
    type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
    openIdConnectUrl?: string;
    scopes: string[];
    in?: 'query' | 'header' | 'cookie';
    scheme?: string;
    name?: string;
    flows?: OAuthFlowsObject;
    'x-defaultAccessToken'?: string;
    'x-defaultTokenType'?: string;
    'x-defaultClientId'?: string;
    'x-defaultClientSecret'?: string;
    'x-defaultUsername'?: string;
    'x-defaultPassword'?: string;
    serverValues?: {
        [serverUrl: string]: {
            'x-defaultAccessToken'?: string;
            'x-defaultTokenType'?: string;
            'x-defaultClientId'?: string;
            'x-defaultClientSecret'?: string;
            'x-defaultUsername'?: string;
            'x-defaultPassword'?: string;
            scopes?: string[];
        };
    };
};

declare interface ParsedDescription {
    'x-parsed-md-description'?: GenericObject;
}

declare interface ParsedDescriptionWithSummary extends ParsedDescription {
    'x-parsed-md-summary'?: GenericObject;
}

declare type PasswordOAuthFlowsObject = {
    tokenUrl: string;
    scopes: Record<string, string>;
};

declare type Referenced<T> = T | OpenAPIRef;

export declare function Replay(props: ReplayAppProps): JSX.Element;

declare type ReplayAppProps = {
    activeOperationId?: string;
    activeOperationPointer?: string;
    api?: OpenAPIDefinition;
    settings: InputSettings;
    renderProjectSelect?: () => React.ReactNode;
};

export declare type ReplayOnChangeParams = {
    operations: ChangedOperation[];
    activeMimeName?: string;
    environment?: string;
    environments?: Record<string, {
        [key: string]: string;
    }>;
};

export declare function ReplayOverlay(props: ReplayOverlayProps): JSX.Element;

declare type ReplayOverlayProps = {
    onClose: () => void;
    onLoad?: () => void;
    onRequestChange?: (props: ReplayOnChangeParams) => void;
} & ReplayAppProps;

export declare type ResolvedTheme = 'light' | 'dark';

export declare function resolveTheme(theme: Theme): ResolvedTheme;

declare type Response_2 = ImmutableObject<{
    headers: [string, string][];
    cookies: [string, string][];
    bodyNotStored?: boolean;
    body: string;
    duration: number;
    size: number;
    status: number;
    bodyUsed: boolean;
    arrayBuffer: ArrayBuffer;
}>;

declare type Server = {
    url: string;
    description?: string;
    name?: string;
    variables?: {
        [name: string]: ServerVariable;
    };
};

declare type ServerVariable = {
    enum?: string[];
    default: string;
    description?: string;
};

export declare type Theme = 'light' | 'dark' | 'auto';

declare type TracerName = 'try-it' | 'replay-openapi' | 'desktop';

declare interface XLogo {
    url?: string;
    backgroundColor?: string;
    altText?: string;
    href?: string;
}

declare interface XMetadata {
    apiId?: string;
    [key: string]: unknown;
}

declare interface XMLObject {
    name?: string;
    namespace?: string;
    prefix?: string;
    attribute?: boolean;
    wrapped?: boolean;
}

declare interface XSEO {
    title?: string;
}

export { }
