text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const HttpClient_1 = require("../HttpClient");
  const appId = process.env.VTEX_APP_ID;
  const [runningAppName] = appId ? appId.split('@') : [''];
  const routes = {
      Bucket: (bucket) => `/buckets/${runningAppName}/${bucket}`,
      Metadata: (bucket) => `${routes.Bucket(bucket)}/metadata`,
      MetadataKey: (bucket, key) => `${routes.Metadata(bucket)}/${key}`,
  };
  class Metadata extends HttpClient_1.InfraClient {
      constructor(context, options) {
          super('router', context, options);
          this.getBuckets = (bucket) => {
              return this.http.get(routes.Bucket(bucket), { metric: 'meta-get-buckets' });
          };
          this.list = (bucket, includeValue, limit, nextMarker) => {
              const query = { value: includeValue, _limit: 10 };
              if (limit && limit > 0) {
                  query._limit = limit;
              }
              if (nextMarker) {
                  query._marker = nextMarker;
              }
              const metric = 'meta-list';
              return this.http.get(routes.Metadata(bucket), { params: query, metric });
          };
          this.listAll = (bucket, includeValue) => {
              const query = { value: includeValue, _limit: 1000 };
              const metric = 'meta-list-all';
              return this.http.get(routes.Metadata(bucket), { params: query, metric });
          };
          this.get = (bucket, key) => {
              return this.http.get(routes.MetadataKey(bucket, key), { metric: 'meta-get' });
          };
          this.save = (bucket, key, data) => {
              return this.http.put(routes.MetadataKey(bucket, key), data, { metric: 'meta-save' });
          };
          this.saveAll = (bucket, data) => {
              return this.http.put(routes.Metadata(bucket), data, { metric: 'meta-save-all' });
          };
          this.delete = (bucket, key) => {
              return this.http.delete(routes.MetadataKey(bucket, key), { metric: 'meta-delete' });
          };
          this.deleteAll = (bucket) => {
              return this.http.delete(routes.Metadata(bucket), { metric: 'meta-delete-all' });
          };
          if (runningAppName === '') {
              throw new Error(`Invalid path to access Metadata. Variable VTEX_APP_ID is not available.`);
          }
      }
  }
  exports.Metadata = Metadata;
  