import { ApplicationService, ApplicationBase } from '@themost/common';
import { DataContext } from '@themost/data';

export declare interface OAuth2MethodOptions {
    access_token: string;
}

export declare interface OAuth2AuthorizeUser {
    client_id?: string;
    client_secret?: string;
    username: string;
    password: string;
    grant_type: string;
    scope?: string;
}

export declare interface OAuth2ServiceSettings {
    unattendedExecutionAccount?: string;
    client_id: string;
    client_secret?: string;
    server_uri: string;
    userinfo_uri?: string;
    introspect_uri?: string;
    admin_uri?: string;
    well_known_configuration_uri?: string;
    adminAccount: {
        username: string;
        password: string;
        client_id: string;
        client_secret?: string;
        scope?: string;
    }
}

export declare interface OAuth2UserProfile {
    sub: string;
    name: string;
    preferred_username: string;
    given_name: string;
    family_name: string;
    email: string;
}

export declare interface GenericUser {
     id?: any; 
     additionalType?: string; 
     alternateName?: string; 
     description?: string; 
     givenName?: string; 
     familyName?: string; 
     image?: string; 
     name?: string; 
     url?: string; 
     dateCreated?: Date; 
     dateModified?: Date; 
     createdBy?: any; 
     modifiedBy?: any; 
     lockoutTime?: Date; 
     logonCount?: number; 
     enabled?: boolean; 
     lastLogon?: Date; 
     userCredentials?: {
         userPassword?: string;
         userActivated?: boolean;
         temporary?: boolean;
     }
}

export declare interface OAuth2User {
    id?: any; 
    username?: string; 
    email?: string; 
    enabled?: boolean;
    emailVerified?: boolean;
    firstName?: string; 
    lastName?: string; 
    credentials?: {
        algorithm?: string,
        temporary?: boolean,
        type?: string,
        value?: string
    }
}

export declare class OAuth2ClientService extends ApplicationService {
    get settings(): OAuth2ServiceSettings;
    constructor(app: ApplicationBase)
    getUserInfo(context: DataContext, token: string): Promise<OAuth2UserProfile>;
    getTokenInfo(context: DataContext, token: string): Promise<any>;
    getContextTokenInfo(context: DataContext): Promise<any>;
    authorize(authorizeUser: OAuth2AuthorizeUser): Promise<{ access_token?: string, refresh_token?: string}>;
    getUser(username: string, options: OAuth2MethodOptions): Promise<any>;
    getUserById(user_id: any, options: OAuth2MethodOptions): Promise<any>;
    getUserByEmail(email: string, options: OAuth2MethodOptions): Promise<any>;
    updateUser(user: GenericUser | any, options: OAuth2MethodOptions): Promise<any>;
    createUser(user: GenericUser | any, options: OAuth2MethodOptions): Promise<any>;
    deleteUser(user: { id: any }, options: OAuth2MethodOptions): Promise<any>; 
}