export const Kind = 'Core#WebApiIndex';
export class WebApiIndex {
    kind = Kind;
    /**
     * API title
     */
    title = '';
    /**
     * List of version names stored with this API.
     */
    versions = [];
    /**
     * The latest added version name.
     */
    latest = '';
    /**
     * The API vendor. E.g. RAML 1.0, OAS 3.0, ASYNC 2.0, ...
     */
    vendor = '';
    static isLegacy(api) {
        const legacy = api;
        return !!legacy.type;
    }
    static fromLegacy(api) {
        const { title, type, versions = [], latest } = api;
        const init = {
            kind: Kind,
            title,
            versions,
            latest,
            vendor: type,
        };
        return new WebApiIndex(init);
    }
    constructor(input) {
        let init;
        if (typeof input === 'string') {
            init = JSON.parse(input);
        }
        else if (typeof input === 'object') {
            init = input;
        }
        else {
            init = {
                kind: Kind,
                latest: '',
                title: '',
                vendor: '',
                versions: [],
            };
        }
        this.new(init);
    }
    new(init) {
        const { latest = '', title = '', vendor = '', versions = [] } = init;
        this.latest = latest;
        this.versions = versions;
        this.title = title;
        this.vendor = vendor;
    }
    toJSON() {
        const result = {
            kind: Kind,
            latest: this.latest,
            versions: this.versions,
            title: this.title,
            vendor: this.vendor,
        };
        return result;
    }
}
//# sourceMappingURL=WebApiIndex.js.map