import { Property } from './Property.js';
export const Kind = 'Core#RequestUiMeta';
export class RequestUiMeta {
    kind = Kind;
    /**
     * Body editor metadata.
     */
    body;
    /**
     * URL editor metadata.
     */
    url;
    /**
     * Headers editor metadata.
     */
    headers;
    /**
     * Authorization editor meta.
     */
    authorization;
    /**
     * The currently selected editor in the request editor UI.
     */
    selectedEditor;
    /**
     * Optional configuration of the response view
     */
    response;
    static fromLegacy(old) {
        const { authorization, body, headers, response, url } = old;
        const init = {
            authorization,
            body,
            response,
        };
        if (url) {
            const initUrl = {};
            if (url.delimiter) {
                initUrl.delimiter = url.delimiter;
            }
            if (Array.isArray(url.model) && url.model.length) {
                initUrl.model = url.model.map((i) => Property.fromApiType(i).toJSON());
            }
            init.url = initUrl;
        }
        if (headers) {
            const headersUrl = {};
            if (typeof headers.source === 'boolean') {
                headersUrl.source = headers.source;
            }
            if (Array.isArray(headers.model) && headers.model.length) {
                headersUrl.model = headers.model.map((i) => Property.fromApiType(i).toJSON());
            }
            init.url = headersUrl;
        }
        return new RequestUiMeta(init);
    }
    /**
     * @param input The project item 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 = {};
        }
        this.new(init);
    }
    /**
     * Creates a new object clearing anything that is so far defined.
     */
    new(init) {
        this.body = init.body;
        this.url = init.url;
        this.headers = init.headers;
        this.authorization = init.authorization;
        this.selectedEditor = init.selectedEditor;
        this.response = init.response;
    }
    toJSON() {
        const result = {
            kind: Kind,
        };
        if (this.body) {
            result.body = this.body;
        }
        if (this.url) {
            result.url = this.url;
        }
        if (this.headers) {
            result.headers = this.headers;
        }
        if (this.authorization) {
            result.authorization = this.authorization;
        }
        if (this.response) {
            result.response = this.response;
        }
        if (typeof this.selectedEditor === 'number') {
            result.selectedEditor = this.selectedEditor;
        }
        return result;
    }
}
//# sourceMappingURL=RequestUiMeta.js.map