import { C8yPact, C8yPactConfigKeys, C8yPactConfigOptions, C8yPactID, C8yPactInfo, C8yPactRecord, C8yPactPreprocessor, C8ySchemaGenerator, C8ySchemaMatcher, C8yPactMatcher, C8yPactEnv, C8yPactSaveKeys, C8yPactMode, C8yPactRecordingMode } from "../../shared/c8ypact";
import { C8yPactRunner } from "./runner";
import { C8yAuthOptions } from "../../shared/auth";
import { C8yClient } from "../../shared/c8yclient";
import { FetchClient, IAuthentication } from "@c8y/client";
import { C8yBaseUrl } from "../../shared/types";
declare global {
    namespace Cypress {
        interface Cypress {
            c8ypact: CypressC8yPact;
        }
        interface SuiteConfigOverrides {
            tags?: string[];
            c8ypact?: C8yPactConfigOptions;
        }
        interface TestConfigOverrides {
            tags?: string[];
            c8ypact?: C8yPactConfigOptions;
        }
        interface RuntimeConfigOptions {
            tags?: string[];
            c8ypact?: C8yPactConfigOptions;
        }
    }
    /**
     * Options for saving pact objects.
     */
    interface C8yPactSaveOptions {
        noqueue: boolean;
        modifiedResponse?: Cypress.Response<any>;
        loggedInUser?: string;
        loggedInUserAlias?: string;
    }
    /**
     * C8yPact Cypress interface. Contains all functions and properties to interact and configure
     * processing of C8yPact objects.
     */
    interface CypressC8yPact {
        /**
         * The pact mode for the current tests.
         */
        mode: () => C8yPactMode;
        /**
         * The pact recording mode for the current tests.
         */
        recordingMode: () => C8yPactRecordingMode;
        /**
         * Create a C8yPactID for the current test case.
         */
        getCurrentTestId(): C8yPactID;
        /**
         * The pact object for the current test case. null if there is no recorded pact for current test.
         */
        current: C8yPact | null;
        /**
         * The C8yPactMatcher implementation used to match requests and responses. Default is C8yDefaultPactMatcher.
         * Can be overridden by setting a matcher in C8yPactConfigOptions.
         */
        matcher?: C8yPactMatcher;
        /**
         * The C8yPactPreprocessor implementation used to preprocess the pact objects.
         */
        preprocessor?: C8yPactPreprocessor;
        /**
         * The C8ySchemaGenerator implementation used to generate json schemas from json objects. The
         * implementation of `C8ySchemaGenerator` must support browser runtimes!
         * Default is undefined and schema generation is disabled.
         */
        schemaGenerator?: C8ySchemaGenerator;
        /**
         * The C8ySchemaMatcher implementation used to match json schemas. The schema matcher implementation
         * must support browser runtimes! Default is undefined and schema matching is disabled.
         */
        schemaMatcher?: C8ySchemaMatcher;
        /**
         * Save the given response as a pact record in the pact for the current test case.
         */
        savePact: (response: Cypress.Response<any> | C8yPact | Pick<C8yPact, C8yPactSaveKeys>, client?: C8yClient, options?: C8yPactSaveOptions) => Promise<void>;
        /**
         * Checks if the C8yPact is enabled. Use C8Y_PACT_IGNORE="true" to disable by default.
         */
        isEnabled: () => boolean;
        /**
         * Checks if the C8yPact is enabled and in recording mode. Use C8Y_PACT_MODE="record" to enable recording.
         */
        isRecordingEnabled: () => boolean;
        /**
         * Checks if the C8yPact is enabled and in mocking mode. Use C8Y_PACT_MODE="mock" to enable mocking.
         */
        isMockingEnabled: () => boolean;
        /**
         * Runtime used to run the pact objects. Default is C8yDefaultPactRunner.
         */
        pactRunner?: C8yPactRunner;
        /**
         * Use debugLog to enable logging of debug information to the Cypress debug log.
         */
        debugLog: boolean;
        config: Omit<C8yPactConfigOptions, "id">;
        /**
         * Resolves config values from current test annotation and global config in Cypress.c8ypact.config.
         * If needed also resolves environment variables.
         * @param key The key of the config value to resolve.
         */
        getConfigValue<T = any>(key: C8yPactConfigKeys, defaultValue?: any): T | undefined;
        /**
         * Resolves config values from current test annotation and global config in Cypress.c8ypact.config.
         */
        getConfigValues(): C8yPactConfigOptions;
        /**
         * Loads the pact object for the current test from the pact file. If
         * there is no stored pact object for the current test, null is returned.
         */
        loadCurrent(): Cypress.Chainable<C8yPact | null>;
        /**
         * Resolves all environment variables as a C8yPactEnv object.
         */
        env(): C8yPactEnv;
        /**
         * Create a custom FetchClient from given auth options and baseUrl. Default implementation
         * of FetchClient is C8yPactFetchClient. Override to provide a custom FetchClient implementation to
         * cy.mount. If undefined is returned, cy.mount will not register a custom FetchClient provider.
         */
        createFetchClient(auth: C8yAuthOptions | IAuthentication | undefined, baseUrl: C8yBaseUrl): FetchClient;
        /**
         * Callbacks for hooking into the pact object lifecycle.
         */
        on: CypressC8yPactCallbackOptions;
    }
    export interface CypressC8yPactCallbackOptions {
        /**
         * Called before a request and its response are saved. By returning `undefined`, the
         * request is ignored and not saved. Use for custom preprocessing or filtering of records.
         * @param record The request and response to be saved as `C8yPactRecord`.
         * @returns C8yPactRecord or undefined if the record should be ignored.
         */
        saveRecord?: (record: C8yPactRecord) => C8yPactRecord | undefined;
        /**
         * Called before a record is mocked. By returning `undefined`, the pact is ignored and not mocked.
         * @param record The record to use for creating a mock response.
         * @returns C8yPactRecord or undefined if the record should be ignored.
         */
        mockRecord?: (record: C8yPactRecord | undefined) => C8yPactRecord | undefined;
        /**
         * Called before a pact is saved. By returning `undefined`, the pact is ignored and not saved.
         * @param pact The pact to be saved.
         * @returns C8yPact or undefined if the pact should be ignored.
         */
        savePact?: (pact: C8yPact) => C8yPact | undefined;
        /**
         * Called after a pact has been loaded and initialized as `Cypress.c8ypact.current`.
         * @param pact The pact that has been loaded.
         * @returns C8yPact now used as `Cypress.c8ypact.current`.
         */
        loadPact?: (pact: C8yPact) => void;
        /**
         * Called for matching errors from `cy.c8ymatch` for custom error handling. By providing a custom
         * error handler, the default error handling is disabled. To fail tests for matching errors, you
         * must throw an error in the custom error handler.
         * @param matcher The matcher used to match the request and response.
         * @param record The pact record used for matching.
         * @param options The options used for matching.
         */
        matchingError?: (matcher: C8yPactMatcher | C8ySchemaMatcher, error: Error, options: any) => void;
        /**
         * Called for every mocha suite started.
         * @param titlePath The title path including parent suite names
         */
        suiteStart?: (titlePath: string[]) => void;
    }
    /**
     * The C8yPactNextRecord contains a single pact record and the info object.
     */
    type C8yPactNextRecord = {
        record: C8yPactRecord;
        info?: C8yPactInfo;
    };
}
