export const Kind = 'Core#Provider';
export class Provider {
    kind = Kind;
    /**
     * The URL to the provider
     */
    url;
    /**
     * The name to the provider
     */
    name;
    /**
     * The email to the provider
     */
    email;
    /**
     * @param input The provider definition used to restore the state.
     */
    constructor(input) {
        let init;
        if (typeof input === 'string') {
            init = JSON.parse(input);
        }
        else if (typeof input === 'object') {
            init = input;
        }
        else {
            init = {
                kind: Kind,
            };
        }
        this.new(init);
    }
    /**
     * Creates a new provider clearing anything that is so far defined.
     *
     * Note, this throws an error when the provider is not a provider object.
     */
    new(init) {
        if (!Provider.isProvider(init)) {
            throw new Error(`Not a provider.`);
        }
        const { url, email, name } = init;
        this.kind = Kind;
        this.name = name;
        this.email = email;
        this.url = url;
    }
    /**
     * Checks whether the input is a definition of a provider.
     */
    static isProvider(input) {
        const typed = input;
        if (input && typed.kind === Kind) {
            return true;
        }
        return false;
    }
    toJSON() {
        const result = {
            kind: Kind,
        };
        if (this.url) {
            result.url = this.url;
        }
        if (this.email) {
            result.email = this.email;
        }
        if (this.name) {
            result.name = this.name;
        }
        return result;
    }
}
//# sourceMappingURL=Provider.js.map