import { nanoid } from '../../nanoid.js';
export const Kind = 'Core#UserIdentity';
export class UserIdentity {
    kind = Kind;
    key = '';
    userId = '';
    provider = 'google';
    providerId = '';
    emailVerified = false;
    hostDomain;
    constructor(input) {
        let init;
        if (typeof input === 'string') {
            init = JSON.parse(input);
        }
        else if (typeof input === 'object') {
            init = input;
        }
        else {
            init = {
                kind: Kind,
                key: nanoid(),
                userId: '',
                provider: 'google',
                providerId: '',
                emailVerified: false,
            };
        }
        this.new(init);
    }
    new(init) {
        if (!UserIdentity.isUserIdentity(init)) {
            throw new Error(`Not a UserIdentity.`);
        }
        const { key = nanoid(), emailVerified, provider, providerId, userId, hostDomain } = init;
        this.kind = Kind;
        this.key = key;
        this.provider = provider;
        this.providerId = providerId;
        this.userId = userId;
        this.emailVerified = emailVerified;
        if (hostDomain) {
            this.hostDomain = hostDomain;
        }
        else {
            this.hostDomain = undefined;
        }
    }
    static isUserIdentity(input) {
        const typed = input;
        if (!input || typed.kind !== Kind) {
            return false;
        }
        return true;
    }
    toJSON() {
        const result = {
            kind: Kind,
            key: this.key,
            provider: this.provider,
            providerId: this.providerId,
            userId: this.userId,
            emailVerified: this.emailVerified,
        };
        if (this.hostDomain) {
            result.hostDomain = this.hostDomain;
        }
        return result;
    }
}
//# sourceMappingURL=UserIdentity.js.map