"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var api_explorer_1 = require("./api-explorer");
var request_1 = require("../../client/api/request");
/**
 * Create an ApiExplorer from an Open Api spec
 */
var OpenApiFactory = /** @class */ (function () {
    function OpenApiFactory() {
    }
    OpenApiFactory.create = function (spec) {
        var api = new api_explorer_1.ApiExplorer();
        for (var path in spec.paths) {
            var pathInfo = spec.paths[path];
            var lwm2mPath = pathInfo['x-lwm2m'];
            for (var method in spec.paths[path]) {
                if (['get', 'put', 'post', 'delete'].indexOf(method) >= 0) {
                    var methodType = void 0;
                    switch (method) {
                        case 'get':
                            methodType = request_1.MethodType.GET;
                            break;
                        case 'put':
                            methodType = request_1.MethodType.PUT;
                            break;
                        case 'post':
                            methodType = request_1.MethodType.POST;
                            break;
                        default:
                            continue;
                    }
                    var operation = pathInfo[method];
                    var info = {
                        operation: operation,
                        path: path,
                        method: methodType,
                        lwm2mPath: lwm2mPath
                    };
                    api.setResource(info);
                }
                else {
                    console.warn("Skip " + method);
                }
            }
        }
        return api;
    };
    return OpenApiFactory;
}());
exports.OpenApiFactory = OpenApiFactory;
