"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MetadataProvider = void 0;
const session_1 = require("../../../session");
const abstract_content_provider_1 = require("../../abstract-content-provider");
const data_accessor_1 = require("../../data-accessor/data-accessor");
const helpers_1 = require("./helpers");
const constants_1 = require("../../../constants");
const util_1 = require("../../../util");
/** @internal */
class MetadataProvider extends abstract_content_provider_1.AbstractContentProvider {
    constructor(session, tableBuilder) {
        super(session);
        this.tableBuilder = tableBuilder;
        this.apiGroup = 'tsi';
        this.endpointName = 'metadata';
        MetadataProvider.validateSession(session);
        this.dataAccessor = new data_accessor_1.DataAccessorImpl(session);
    }
    async getGlobal(params) {
        (0, util_1.validateRequired)(params, ['types'], 'HistoricalPricing.Metadata.Global');
        const dataAccessorContentQuery = (0, helpers_1.convertParamsToQuery)(Object.assign(Object.assign({}, params), params.extendedParams));
        const requestParams = {
            url: `${constants_1.TSI_ENDPOINT_ROOT}${this.getEndpointPath('global-metadata')}`,
            dataAccessorContentQuery,
        };
        const response = await this.dataAccessor.getData(requestParams);
        return this.toContentResponse(response);
    }
    async getInstrument(params) {
        (0, util_1.validateRequired)(params, ['types', 'name'], 'HistoricalPricing.Metadata.Instrument');
        const dataAccessorContentQuery = (0, helpers_1.convertParamsToQuery)(Object.assign(Object.assign({}, params), params.extendedParams));
        const requestParams = {
            url: `${constants_1.TSI_ENDPOINT_ROOT}${this.getEndpointPath('instrument-metadata')}`,
            dataAccessorContentQuery,
        };
        const response = await this.dataAccessor.getData(requestParams);
        return this.toContentResponse(response);
    }
    async getViewlist(params) {
        (0, util_1.validateRequired)(params, ['name'], 'HistoricalPricing.Metadata.Viewlist');
        const dataAccessorContentQuery = (0, helpers_1.convertParamsToQuery)(Object.assign(Object.assign({}, params), params.extendedParams));
        const requestParams = {
            url: `${constants_1.TSI_ENDPOINT_ROOT}${this.getEndpointPath('viewlist')}`,
            dataAccessorContentQuery,
        };
        const response = await this.dataAccessor.getData(requestParams);
        return this.toContentResponse(response);
    }
    async getPartialbar(params) {
        (0, util_1.validateRequired)(params, ['name'], 'HistoricalPricing.Metadata.Partialbar');
        const dataAccessorContentQuery = (0, helpers_1.convertParamsToQuery)(Object.assign(Object.assign({}, params), params.extendedParams));
        const requestParams = {
            url: `${constants_1.TSI_ENDPOINT_ROOT}${this.getEndpointPath('partialbar')}`,
            dataAccessorContentQuery,
        };
        const response = await this.dataAccessor.getData(requestParams);
        const buildTable = () => this.tableBuilder.build(response.data);
        return this.toContentResponse(response, buildTable);
    }
    static validateSession(session) {
        if (session instanceof session_1.Platform || session instanceof session_1.Container) {
            throw new Error('TSI Service is available only in Desktop session yet!');
        }
    }
}
exports.MetadataProvider = MetadataProvider;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV0YWRhdGEtcHJvdmlkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvY29udGVudC9oaXN0b3JpY2FsLXByaWNpbmcvbWV0YWRhdGEvbWV0YWRhdGEtcHJvdmlkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsOENBQThFO0FBQzlFLCtFQUEwRTtBQUUxRSxxRUFBcUU7QUFFckUsdUNBQWlEO0FBQ2pELGtEQUF1RDtBQUN2RCx3Q0FBaUQ7QUFPakQsZ0JBQWdCO0FBQ2hCLE1BQWEsZ0JBQTRDLFNBQVEsbURBQXVCO0lBS3BGLFlBQVksT0FBZ0IsRUFBVSxZQUEwQztRQUM1RSxLQUFLLENBQUMsT0FBTyxDQUFDLENBQUM7UUFEbUIsaUJBQVksR0FBWixZQUFZLENBQThCO1FBSnpFLGFBQVEsR0FBdUIsS0FBSyxDQUFDO1FBQ3JDLGlCQUFZLEdBQUcsVUFBVSxDQUFDO1FBSzdCLGdCQUFnQixDQUFDLGVBQWUsQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUMxQyxJQUFJLENBQUMsWUFBWSxHQUFHLElBQUksZ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