import { CtxOrReq } from 'next-auth/client/_utils';
import { LiteralUnion, ClientSafeProvider, SignOutParams, SignOutResponse, SignInOptions, SignInAuthorizationParams, SignInResponse } from 'next-auth/react';
import { BuiltInProviderType, RedirectableProviderType } from 'next-auth/providers/index';

type JWT = {
    email: string;
    sub: string;
    id: string;
    iat: number;
    exp: number;
    jti: string;
    loading: boolean;
};
type ActiveSession = {
    loading: boolean;
    id: string;
    email: string;
    expires: string;
    user?: {
        id: string;
        name: string;
        image: string;
        email: string;
        emailVerified: void | Date;
    };
};
type NonErrorSession = JWT | ActiveSession | null | undefined;
type AuthState = {
    basePath: string;
    baseUrl: string;
    lastSync: number;
    getSession: (...args: any[]) => void;
    session: NonErrorSession | undefined | null;
    loading: boolean;
};
type ListenerParams = {
    key: ListenerKeys;
    next: any;
    prev: any;
};
type Listener = (callback: ListenerParams) => void;
type ListenerKeys = 'basePath' | 'baseUrl' | 'lastSync' | 'getSession' | 'session' | 'loading';
type AuthConfig = Config & {
    listenerKeys?: Array<ListenerKeys>;
};
type Config = {
    basePath?: string;
    baseUrl?: string;
    init?: RequestInit;
};
type PartialAuthorizer = null | {
    state?: {
        baseUrl?: string;
        basePath?: string;
        session?: {
            user?: {
                email?: string | undefined;
            };
        };
    };
    requestInit?: RequestInit | undefined;
};

type WarningCode = 'NEXTAUTH_URL' | 'NO_SECRET' | 'TWITTER_OAUTH_2_BETA' | 'DEBUG_ENABLED';
/**
 * Override any of the methods, and the rest will use the default logger.
 *
 * [Documentation](https://next-auth.js.org/configuration/options#logger)
 */
interface LoggerInstance extends Record<string, (...args: any) => any> {
    warn: (code: WarningCode) => void;
    error: (code: string, 
    /**
     * Either an instance of (JSON serializable) Error
     * or an object that contains some debug information.
     * (Error is still available through `metadata.error`)
     */
    metadata: Error | {
        error: Error;
        [key: string]: unknown;
    }) => void;
    debug: (code: string, metadata: unknown) => void;
}

type GetSessionParams = CtxOrReq & {
    event?: 'storage' | 'timer' | 'hidden' | string;
    triggerEvent?: boolean;
    broadcast?: boolean;
    baseUrl?: string;
    init?: RequestInit;
};
declare enum State {
    SESSION = "getSession"
}
declare class Authorizer {
    state: AuthState;
    logger: LoggerInstance;
    requestInit?: RequestInit;
    addListener: (cb: Listener) => void;
    removeListener: (cb: Listener) => void;
    status: null | State;
    constructor(config?: AuthConfig);
    sync(event?: 'storage' | 'timer' | 'hidden' | 'poll' | 'visibilitychange'): Promise<void>;
    set baseUrl(val: string);
    get baseUrl(): string;
    configure(config?: Config): this;
    sanitize(): PartialAuthorizer;
    initialize(params?: {
        baseUrl?: string;
        session?: NonErrorSession | null | undefined;
        event?: 'storage' | 'timer' | 'hidden' | 'poll' | 'visibilitychange';
    }): Promise<void>;
    get apiBaseUrl(): string;
    fetchData<T = any>(url: string, init?: RequestInit): Promise<T | undefined>;
    fetchFormData<T = {
        url: string;
    }>(url: string, init: RequestInit): Promise<{
        data: T;
        status: number;
        ok: boolean;
        url: string;
    } | undefined>;
    getProviders(): Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
    getCsrfToken(): Promise<string | undefined>;
    getSession(params?: GetSessionParams): Promise<NonErrorSession>;
    refreshSession(): Promise<NonErrorSession>;
    signOut<R extends boolean = true>(options?: SignOutParams<R> & {
        baseUrl?: string;
        auth?: Authorizer | PartialAuthorizer;
        fetchUrl?: string;
        basePath?: string;
    }): Promise<R extends true ? undefined : SignOutResponse>;
    signIn<P extends RedirectableProviderType | undefined = undefined>(provider?: LiteralUnion<P extends RedirectableProviderType ? P | BuiltInProviderType : BuiltInProviderType>, options?: SignInOptions & {
        baseUrl?: string;
        init?: ResponseInit;
        fetchUrl?: string;
        auth?: Authorizer | PartialAuthorizer;
    }, authorizationParams?: SignInAuthorizationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>;
    signUp(options: {
        baseUrl?: string;
        init?: ResponseInit;
        fetchUrl?: string;
        newTenantName?: string;
        createTenant?: string | boolean;
        email: string;
        password: string;
        auth?: Authorizer | PartialAuthorizer;
        tenantId?: string;
        callbackUrl?: string;
        redirect?: boolean;
    }): Promise<any>;
}
declare const authorizer: Authorizer;
declare const auth: Authorizer;
declare const getSession: (params?: GetSessionParams) => Promise<NonErrorSession>;
declare const getCsrfToken: () => Promise<string | undefined>;
declare const getProviders: () => Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
declare const signOut: typeof authorizer.signOut;
declare const signIn: typeof authorizer.signIn;

export { type ActiveSession, type AuthConfig, type AuthState, Authorizer, type JWT, type Listener, type ListenerKeys, type ListenerParams, type PartialAuthorizer, type NonErrorSession as Session, auth, getCsrfToken, getProviders, getSession, signIn, signOut };
