import { ISingleEndpointOpts, GenericAuthArgs, ExpressSupport } from '@sphereon/ssi-express-support';
import { Request, Response, Router, Express } from 'express';
import { CreateAuthorizationRequestPayload, CreateAuthorizationResponsePayload, VerifiedData } from '@sphereon/did-auth-siop';
import { IPDManager } from '@sphereon/ssi-sdk.pd-manager';
import { AuthorizationRequestStateStatus, AuthorizationResponseStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common';
import { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth';
import { IAgentContext, ICredentialVerifier, TAgent } from '@veramo/core';

interface ComponentOptions {
    /**
     * Component options for data/ECC.
     */
    data?: {
        /**
         * Scale factor for data/ECC dots.
         * @default 1
         */
        scale?: number;
    };
    /**
     * Component options for timing patterns.
     */
    timing?: {
        /**
         * Scale factor for timing patterns.
         * @default 1
         */
        scale?: number;
        /**
         * Protector for timing patterns.
         * @default false
         */
        protectors?: boolean;
    };
    /**
     * Component options for alignment patterns.
     */
    alignment?: {
        /**
         * Scale factor for alignment patterns.
         * @default 1
         */
        scale?: number;
        /**
         * Protector for alignment patterns.
         * @default false
         */
        protectors?: boolean;
    };
    /**
     * Component options for alignment pattern on the bottom-right corner.
     */
    cornerAlignment?: {
        /**
         * Scale factor for alignment pattern on the bottom-right corner.
         * @default 1
         */
        scale?: number;
        /**
         * Protector for alignment pattern on the bottom-right corner.
         * @default true
         */
        protectors?: boolean;
    };
}
interface QRCodeOpts {
    /**
     * Size of the QR code in pixel.
     *
     * @defaultValue 400
     */
    size?: number;
    /**
     * Size of margins around the QR code body in pixel.
     *
     * @defaultValue 20
     */
    margin?: number;
    /**
     * Error correction level of the QR code.
     *
     * Accepts a value provided by _QRErrorCorrectLevel_.
     *
     * For more information, please refer to [https://www.qrcode.com/en/about/error_correction.html](https://www.qrcode.com/en/about/error_correction.html).
     *
     * @defaultValue 0
     */
    correctLevel?: number;
    /**
     * **This is an advanced option.**
     *
     * Specify the mask pattern to be used in QR code encoding.
     *
     * Accepts a value provided by _QRMaskPattern_.
     *
     * To find out all eight mask patterns, please refer to [https://en.wikipedia.org/wiki/File:QR_Code_Mask_Patterns.svg](https://en.wikipedia.org/wiki/File:QR_Code_Mask_Patterns.svg)
     *
     * For more information, please refer to [https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Masking](https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Masking).
     */
    maskPattern?: number;
    /**
     * **This is an advanced option.**
     *
     * Specify the version to be used in QR code encoding.
     *
     * Accepts an integer in range [1, 40].
     *
     * For more information, please refer to [https://www.qrcode.com/en/about/version.html](https://www.qrcode.com/en/about/version.html).
     */
    version?: number;
    /**
     * Options to control components in the QR code.
     *
     * @deafultValue undefined
     */
    components?: ComponentOptions;
    /**
     * Color of the blocks on the QR code.
     *
     * Accepts a CSS &lt;color&gt;.
     *
     * For more information about CSS &lt;color&gt;, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
     *
     * @defaultValue "#000000"
     */
    colorDark?: string;
    /**
     * Color of the empty areas on the QR code.
     *
     * Accepts a CSS &lt;color&gt;.
     *
     * For more information about CSS &lt;color&gt;, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
     *
     * @defaultValue "#ffffff"
     */
    colorLight?: string;
    /**
     * Automatically calculate the _colorLight_ value from the QR code's background.
     *
     * @defaultValue true
     */
    autoColor?: boolean;
    /**
     * Background image to be used in the QR code.
     *
     * Accepts a `data:` string in web browsers or a Buffer in Node.
     *
     * @defaultValue undefined
     */
    backgroundImage?: string | Buffer;
    /**
     * Color of the dimming mask above the background image.
     *
     * Accepts a CSS &lt;color&gt;.
     *
     * For more information about CSS &lt;color&gt;, please refer to [https://developer.mozilla.org/en-US/docs/Web/CSS/color_value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
     *
     * @defaultValue "rgba(0, 0, 0, 0)"
     */
    backgroundDimming?: string;
    /**
     * GIF background image to be used in the QR code.
     *
     * @defaultValue undefined
     */
    gifBackground?: ArrayBuffer;
    /**
     * Use a white margin instead of a transparent one which reveals the background of the QR code on margins.
     *
     * @defaultValue true
     */
    whiteMargin?: boolean;
    /**
     * Logo image to be displayed at the center of the QR code.
     *
     * Accepts a `data:` string in web browsers or a Buffer in Node.
     *
     * When set to `undefined` or `null`, the logo is disabled.
     *
     * @defaultValue undefined
     */
    logoImage?: string | Buffer;
    /**
     * Ratio of the logo size to the QR code size.
     *
     * @defaultValue 0.2
     */
    logoScale?: number;
    /**
     * Size of margins around the logo image in pixels.
     *
     * @defaultValue 6
     */
    logoMargin?: number;
    /**
     * Corner radius of the logo image in pixels.
     *
     * @defaultValue 8
     */
    logoCornerRadius?: number;
    /**
     * @deprecated
     *
     * Ratio of the real size to the full size of the blocks.
     *
     * This can be helpful when you want to make more parts of the background visible.
     *
     * @deafultValue 0.4
     */
    dotScale?: number;
}

type SiopFeatures = 'rp-status' | 'siop';
interface ISIOPv2RPRestAPIOpts {
    enableFeatures?: SiopFeatures[];
    endpointOpts?: {
        basePath?: string;
        trustProxy?: boolean | Array<string>;
        globalAuth?: GenericAuthArgs & {
            secureSiopEndpoints?: boolean;
        };
        webappCreateAuthRequest?: ICreateAuthRequestWebappEndpointOpts;
        webappDeleteAuthRequest?: ISingleEndpointOpts;
        webappGetDefinitions?: ISingleEndpointOpts;
        webappAuthStatus?: ISingleEndpointOpts;
        siopVerifyAuthResponse?: ISingleEndpointOpts;
        siopGetAuthRequest?: ISingleEndpointOpts;
    };
}
interface ICreateAuthRequestWebappEndpointOpts extends ISingleEndpointOpts {
    siopBaseURI?: string;
    qrCodeOpts?: QRCodeOpts;
    webappAuthStatusPath?: string;
    webappBaseURI?: string;
    responseRedirectURI?: string;
}
type IRequiredPlugins = ICredentialVerifier & ISIOPv2RP & IPDManager;
type IRequiredContext = IAgentContext<IRequiredPlugins>;
type CreateAuthorizationRequestPayloadRequest = Request<Record<string, never>, any, CreateAuthorizationRequestPayload, Record<string, never>>;
type CreateAuthorizationResponsePayloadResponse = Response<CreateAuthorizationResponsePayload>;
type DeleteAuthorizationRequest = Request<DeleteAuthorizationRequestPathParameters, any, Record<string, any>, Record<string, any>>;
type DeleteAuthorizationRequestPathParameters = {
    correlationId: string;
};
type GetAuthorizationRequestStatus = Request<GetAuthorizationRequestStatusPathParameters, any, Record<string, any>, Record<string, any>>;
type GetAuthorizationRequestStatusPathParameters = {
    correlationId: string;
};
type RequestError = {
    status: number;
    message: string;
    error_details?: string;
};
interface AuthStatusResponse {
    status: AuthorizationRequestStateStatus | AuthorizationResponseStateStatus;
    correlation_id: string;
    query_id: string;
    last_updated: number;
    verified_data?: VerifiedData;
    error?: RequestError;
}

declare function verifyAuthResponseSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
declare function getAuthRequestSIOPv2Endpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
declare function buildQueryIdFilter(queryId: string, tenantId?: string, version?: string): ({
    version?: string | undefined;
    tenantId?: string | undefined;
    queryId: string;
} | {
    id: string;
})[];

declare function createAuthRequestUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts): void;
declare function removeAuthRequestStateUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
declare function authStatusUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;
declare function getDefinitionsEndpoint(router: Router, context: IRequiredContext, opts?: ISingleEndpointOpts): void;

declare class SIOPv2RPApiServer {
    private readonly _express;
    private readonly _router;
    private readonly _agent;
    private readonly _opts?;
    private readonly _basePath;
    private readonly OID4VP_OPENAPI_FILE;
    private readonly OID4VP_SWAGGER_URL;
    constructor(args: {
        agent: TAgent<IRequiredPlugins>;
        expressSupport: ExpressSupport;
        opts?: ISIOPv2RPRestAPIOpts;
    });
    /**
     * Sets up Swagger UI for API documentation.
     * Spec source priority:
     * 1. OID4VP_OPENAPI_SPEC env var (URL or file path)
     * 2. Bundled universal-OID4VP-openapi.yaml file
     * 3. Fallback to SwaggerHub URL
     */
    private setupSwaggerUi;
    get express(): Express;
    get router(): Router;
    get agent(): TAgent<ISIOPv2RP>;
    get opts(): ISIOPv2RPRestAPIOpts | undefined;
}

export { type AuthStatusResponse, type ComponentOptions, type CreateAuthorizationRequestPayloadRequest, type CreateAuthorizationResponsePayloadResponse, type DeleteAuthorizationRequest, type DeleteAuthorizationRequestPathParameters, type GetAuthorizationRequestStatus, type GetAuthorizationRequestStatusPathParameters, type ICreateAuthRequestWebappEndpointOpts, type IRequiredContext, type IRequiredPlugins, type ISIOPv2RPRestAPIOpts, type QRCodeOpts, type RequestError, SIOPv2RPApiServer, type SiopFeatures, authStatusUniversalOID4VPEndpoint, buildQueryIdFilter, createAuthRequestUniversalOID4VPEndpoint, getAuthRequestSIOPv2Endpoint, getDefinitionsEndpoint, removeAuthRequestStateUniversalOID4VPEndpoint, verifyAuthResponseSIOPv2Endpoint };
