import { FileResponse } from '@tauri-apps/plugin-dialog';
import { ImmutableObject } from '@hookstate/core';
import { JSX as JSX_2 } from 'react/jsx-runtime';
import { NamedExoticComponent } from 'react';
import { ReactElement } from 'react';

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 = {
    sourcePath: SourcePath;
    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 | undefined;

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

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

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

declare type InputSettings = {
    corsProxyUrl?: string;
    mockServer?: MockServer;
    disableCollectionsTab?: boolean;
    disableWorkflowTab?: boolean;
    disableDraft?: boolean;
    oAuth2RedirectURI?: string | null;
    inline?: boolean;
    environment?: string;
    apiId?: string;
    predefinedEnvValues?: Record<string, Record<string, string>>;
    certificates?: Certificate[];
    storageKey?: string;
    convertOperationToReplayValue?: ConvertOperationFunction;
    getOperationUrl?: GetOperationURLFunction;
};

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;
    content: ReactElement;
    mountId?: string;
    className?: string;
};

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

declare type OpenAPIOperation = {
    id: string;
    sourceId?: 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 function openFile({ name, extensions, multiple, }: {
    name: string;
    extensions: string[];
    multiple: boolean;
}): Promise<FileResponse | string | null>;

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[];
};

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;
};

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

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

declare type ReplayAppProps = {
    activeOperationId?: string;
    source?: Omit<Source, 'id'>;
    settings: InputSettings;
};

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

export declare function ReplayOverlay({ onClose, onLoad, onRequestChange, ...props }: ReplayOverlayProps): JSX_2.Element;

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

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

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

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

declare type Source = {
    id: string;
    type: 'openapi' | 'arazzo';
    path?: string;
    data: Record<string, any>;
};

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

export declare const utils: {
    openFile: typeof openFile;
};

export { }

declare global {
    interface Window {
        __TAURI__: {
            http: {
                fetch: typeof globalThis.fetch;
            };
        };
    }
}
