import { Auth, FrontcraftIfc, FrontcraftFeatureIfc, User, SomeOf } from '../../../../../../backend/Types/Types';
import { saltedHash } from '../../../../../../backend/Util/hash';
import { RPCSocket, ConnectedSocket } from 'rpclibrary';

export class IApiService{
    getUnprivilegedSocket: () => ConnectedSocket<FrontcraftIfc>
    getAuth: () => Auth | undefined
    checkLogin: () => Promise<boolean>
    initialize: () => Promise<any>
    getCurrentUser: () => User
    login: (username: string, password: string) => Promise<RPCSocket & SomeOf<FrontcraftFeatureIfc>>
    kick: () => Promise<void>
    logout: () => Promise<void>
    get: <K extends (keyof FrontcraftIfc | keyof FrontcraftFeatureIfc)>(feature : K) => K extends keyof FrontcraftIfc
                                                                                      ? FrontcraftIfc[K]
                                                                                      : K extends keyof FrontcraftFeatureIfc
                                                                                      ? (FrontcraftFeatureIfc[K] | void)
                                                                                      : never
}

export async function hash(value:string) : Promise<string>{
    return saltedHash(value, "")
}

export const GuestUser: User = {
    username: 'Guest',
    pwhash: '',
    rank: 'Guest'
}