import { TenantUser } from '@codiac.io/codiac-common/security';
import { IBetterLogger } from '@codiac.io/codiac-common/IBetterLogger';
import { UserContext } from '@codiac.io/codiac-relay-contracts';
import { CliEnviro } from './ops/entities';
import { IAuthClient } from './apis/auth-client/i-auth-client';
/** Simply deserializes the currently cached user context from its config file.
 * This class exists so that the load methods can be called before an api client gets instantiated. */
export declare class UserContextLoader {
    private cliEnviro;
    private logger;
    constructor(cliEnviro: CliEnviro, logger: IBetterLogger);
    /** (context is Machine-User scoped)
     *  Attempts to load the user and select from their tenant tokens and enterprise contexts persisted locally by the CLI.
     *  Returns undefined for not found and throws any encountered exceptions.
     *
     * The full user context will STILL be returned no matter what,
     * whether or not there was a matching tenant profile.
     * But if the context has no matching tenant profile,
     * the CURRENT tenantCode, token, and enterprise will be undefined (ie: a tenantless user, a principal user).
     *
     * This way, if the cache is stale, the current user can still authenticate to refresh it.
     * eg: if the user was just seconds ago added to a tenant,
     * this pattern can pick up the new profile from the remote auth service without requiring a manual login.
     *
     * @param tenantCode Enforces the given tenantCode. When set, current context will be ignored if it does not match it.
     * */
    loadUserContext(tenantCode?: string | undefined): UserContext | undefined;
    /** Mutates the given object's current tenant properties
     * (currentToken, currentEnterprise, currentTenantCode, tokenExpiration)
     * to those of the current tenant code,
     * by either allowing the current state,
     * or by applying any relevant tenant profile that exists onboard the given context object.
     *
     * If no matching profile exists, "current" properties will be set to undefined (like a principal user),
     * but the context itself WILL STILL BE RETURNED.
    */
    trySetCurrentProfileFor(tenantCode: string, userContext: UserContext): void;
    /** Obliterates the current user state by deleting the context file. */
    clearUserContext(): Promise<void>;
}
/** Provides cruds for the user context, persisting to the local context config file. */
export declare class UserContextManager {
    private cliEnviro;
    private authClient;
    private logger;
    constructor(cliEnviro: CliEnviro, authClient: IAuthClient, logger: IBetterLogger);
    private loader;
    /** Extends the user token so we can get the user's tenant profiles.
     *  If the token is expired, or something has changed, it fails.
     *  Throws any exceptions.
     */
    refreshUserContext(currentContext: UserContext): Promise<{
        context?: UserContext;
        user?: TenantUser;
    }>;
    /** Writes the given UserContext to the Toyhauler user config folder on the local machine.
     * TODO:  Consider writing this to the cache folder instead of the config folder.
     * Throws any encountered exceptions. */
    writeUserContext(userContext: UserContext): void;
    /** Persists the current user, its token, and its tenantCode to the user context
     *  and the userContext file stored on the local machine. */
    saveToUserContext(currentContext: UserContext | undefined, userName: string, token: string, tenantCode?: string, tokenExpiration?: Date, roles?: string[]): Promise<UserContext>;
}
