import { getUser } from 'talon/configProvider';
import { assert } from 'talon/utils';

/**
 * Resolves '@salesforce/user' resources.
 */
export default {
    scope: 'user',

    resolve(resource) {
        const user = getUser();

        assert(user, `Can't resolve @salesforce/user/${resource} because user is falsy`);

        switch (resource) {
            case 'Id':
                return user.id;
            case 'isGuest':
                return user.isGuest;
            default:
                throw new Error(
                    `Unknown resource, cannot resolve dependency '@salesforce/user/${resource}'`
                );
        }
    },
};
