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';
import { State } from '@hookstate/core';

declare enum ApiKeyLocation {
    Query = "Query",
    Header = "Header",
    Cookie = "Cookie"
}

declare type App = {
    title: string;
    id: string;
    credentials?: AppCredential[];
};

declare type AppCredential = {
    id: string;
    clientId?: string;
    clientSecret?: string;
    stage?: string;
    issuedAt: string;
    expiresAt: string;
    status: string;
    valueToUseInHeader: 'clientId' | 'clientSecret';
};

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

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

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

declare type CollectionsFolder = {
    id: string;
    name: string;
    items: CollectionsItem[];
    state: CollectionsItemState;
};

declare type CollectionsItem = {
    type: CollectionsItemType;
    value: CollectionsFolder | CollectionsRequest;
};

declare enum CollectionsItemState {
    Normal = "Normal",
    Edit = "Edit",
    Draft = "Draft"
}

declare enum CollectionsItemType {
    Folder = "folder",
    Request = "request"
}

declare type CollectionsRequest = {
    id: string;
    state: CollectionsItemState;
    name: string;
    request: Request_2;
    response: Response_2 | null;
};

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

declare type Environment = {
    id: string;
    url?: string;
    name: string;
    variables: EnvironmentVariable[];
    state: EnvironmentState;
    canBeRemoved: boolean;
    canBeEdited: boolean;
};

declare enum EnvironmentState {
    Normal = "Normal",
    Edit = "Edit",
    Draft = "Draft"
}

declare type EnvironmentVariable = {
    id: string;
    name: string;
    value: string;
    type: EnvironmentVariableType;
    canBeRemoved: boolean;
    canBeEdited: boolean;
    isSecret?: boolean;
    readonlyName?: boolean;
};

declare enum EnvironmentVariableType {
    Server = "Server",
    ServerUrl = "ServerUrl",
    Path = "Path",
    UserCreated = "UserCreated",
    Security = "Security"
}

declare type FormDataParameter = Parameter & {
    type: InputType;
    files: FileList | null;
};

declare const globalState: State<    {
requestController: AbortController | undefined;
request: {
method: string;
url: string;
security: {
securitySchemeVariants: SecuritySchemeVariantType[];
selectedSecuritySchemeId: string;
securities: {
securityType: SecurityTypes;
securitySchemeId: string;
"Basic Auth": {
username: string;
password: string;
};
JWT: {
token: string;
};
"Digest Auth": {
username: string;
password: string;
nc: string;
realm: string | undefined;
nonce: string | undefined;
opaque: string | undefined;
qop: string | undefined;
algorithm: string | undefined;
cnonce: string | undefined;
};
"API key": {
location: ApiKeyLocation;
name: string;
key: string;
};
"OAuth 2.0": {
documentedOAuth2Types: SecurityFlows[];
grantType: SecurityFlows;
authRequestExtraParams: Parameter[];
tokenRequestExtraParams: SecurityDataParameter[];
"Client Credentials": {
clientId: string;
clientSecret: string;
clientAssertion: string;
tokenUrl: string;
scopes: Parameter[];
accessToken: string;
};
"Client Credentials with JWT Assertion": {
clientId: string;
clientSecret: string;
clientAssertion: string;
tokenUrl: string;
scopes: Parameter[];
accessToken: string;
};
"Authorization Code": {
clientId: string;
clientSecret: string;
tokenUrl: string;
authorizationUrl: string;
callbackUrl: string;
availableScopes: string[];
scopes: Parameter[];
codeVerifier: string;
codeChallenge: string;
accessToken: string;
};
Implicit: {
clientId: string;
authorizationUrl: string;
callbackUrl: string;
availableScopes: string[];
scopes: Parameter[];
accessToken: string;
};
Password: {
username: string;
password: string;
clientId: string;
clientSecret: string;
tokenUrl: string;
accessToken: string;
};
};
"OpenID Connect": {
openIdConnectUrl: string;
userInfoUrl: string;
documentedOAuth2Types: SecurityFlows[];
grantType: SecurityFlows;
authRequestExtraParams: Parameter[];
tokenRequestExtraParams: SecurityDataParameter[];
"Client Credentials": {
clientId: string;
clientSecret: string;
clientAssertion: string;
tokenUrl: string;
scopes: Parameter[];
accessToken: string;
};
"Client Credentials with JWT Assertion": {
clientId: string;
clientSecret: string;
clientAssertion: string;
tokenUrl: string;
scopes: Parameter[];
accessToken: string;
};
"Authorization Code": {
clientId: string;
clientSecret: string;
tokenUrl: string;
authorizationUrl: string;
callbackUrl: string;
availableScopes: string[];
scopes: Parameter[];
codeVerifier: string;
codeChallenge: string;
accessToken: string;
};
Implicit: {
clientId: string;
authorizationUrl: string;
callbackUrl: string;
availableScopes: string[];
scopes: Parameter[];
accessToken: string;
};
Password: {
username: string;
password: string;
clientId: string;
clientSecret: string;
tokenUrl: string;
accessToken: string;
};
};
}[];
};
body: {
type: string;
content: string;
activeExampleName: string;
formData: {
[x: string]: FormDataParameter[];
};
binary: File | null;
};
queryParameters: Parameter[];
headers: Parameter[];
cookies: Parameter[];
};
isProcessingRequest: boolean;
response: ImmutableObject<    {
headers: [string, string][];
cookies: [string, string][];
body: string;
duration: number;
size: number;
status: number;
bodyUsed: boolean;
arrayBuffer: ArrayBuffer;
}> | null;
requestError: string | null;
history: HistoryItem[];
collections: CollectionsItem[];
operation: Operation | null;
operationUrl: string | undefined;
isLinked: boolean;
environments: Environment[];
selectedEnvironmentId: string | null;
corsProxyUrl: string | undefined;
mockServer: MockServer | undefined;
appsLoadingState: LoadingState;
apps: App[];
apiId: string | undefined;
requestActiveTabIdx: number;
oAuth2RedirectURI: string | null | undefined;
isRequestEditable: boolean;
tokenRequestError: string | null;
definitionUrl: string | undefined;
transactionSource: TransactionSource | null;
showUnsavedChangesModal: boolean;
pendingTransaction: Transaction | null;
pendingTransactionSource: TransactionSource | null;
disableCollectionsTab: boolean | undefined;
certificates: Certificate[];
}, {}>;

declare type HistoryItem = {
    date: number;
    request: Request_2;
    response: Response_2 | null;
};

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

declare type InputType = 'text' | 'file';

declare enum LoadingState {
    Idle = "idle",
    Loading = "loading",
    Success = "success",
    Error = "error"
}

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 enum OAuth2ExtraParamsLocation {
    Body = "Body",
    Header = "Header",
    URL = "URL"
}

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

declare function openFile({ name, extensions, multiple, }: {
    name: string;
    extensions: string[];
    multiple: boolean;
}): Promise<FileResponse | string | null>;

declare type Operation = {
    name: string;
    method: string;
    path: string;
    parameters: OperationParameter[];
    body?: {
        mediaTypes: MediaTypes;
        required?: boolean;
        activeExampleName?: string;
    };
    servers: Server[];
    security?: OperationSecurity[][];
};

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

declare type Parameter = {
    id: string;
    active: boolean;
    key: string;
    value: string;
};

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

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

declare type ReplayAppProps = {
    value?: Operation;
    inline?: boolean;
    operationUrl?: string;
    corsProxyUrl?: string;
    mockServer?: MockServer;
    disableDraft?: boolean;
    environment?: string;
    predefinedEnvValues?: Record<string, Record<string, string>>;
    apiId?: string;
    oAuth2RedirectURI?: string | null;
    definitionUrl?: string;
    disableCollectionsTab?: boolean;
    certificates?: Certificate[];
};

declare type ReplayOnChangeParams = {
    requestValues: {
        cookie?: {
            [key: string]: string;
        };
        header?: {
            [key: string]: string;
        };
        query?: {
            [key: string]: string;
        };
        body?: any;
    } | object;
    activeExampleName?: string;
    activeMimeName?: string;
    activeServer?: Server;
    environment?: string;
    environments?: Record<string, {
        [key: string]: string;
    }>;
    activeSecuritySchemeIds?: 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;

export declare type ReplayState = typeof globalState.value;

declare type Request_2 = typeof globalState.value.request;

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 SecurityDataParameter = Parameter & {
    sendIn: OAuth2ExtraParamsLocation;
};

declare enum SecurityFlows {
    ClientCredentials = "Client Credentials",
    ClientCredentialsWithJwtAssertion = "Client Credentials with JWT Assertion",
    AuthorizationCode = "Authorization Code",
    Implicit = "Implicit",
    Password = "Password"
}

declare type SecuritySchemeVariantType = {
    id: string;
    schemes: string[];
};

declare enum SecurityTypes {
    NoAuth = "No Auth",
    BasicAuth = "Basic Auth",
    DigestAuth = "Digest Auth",
    JWT = "JWT",
    APIKey = "API key",
    OAuth2 = "OAuth 2.0",
    OpenIDConnect = "OpenID Connect"
}

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

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

declare type Transaction = {
    request: Request_2;
    response: Response_2 | null;
};

declare type TransactionSource = {
    id: string;
    type: 'collection';
    name: string;
};

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

export { }

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