text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const request_1 = require("../../../../request");
  const commands_1 = require("../../commands");
  const SpoCommand_1 = require("../../../base/SpoCommand");
  const vorpal = require('../../../../vorpal-init');
  class SpoFeatureEnableCommand extends SpoCommand_1.default {
      get name() {
          return commands_1.default.FEATURE_ENABLE;
      }
      get description() {
          return 'Enables feature for the specified site or web';
      }
      getTelemetryProperties(args) {
          const telemetryProps = super.getTelemetryProperties(args);
          telemetryProps.scope = args.options.scope || 'web';
          telemetryProps.force = args.options.force || false;
          return telemetryProps;
      }
      commandAction(cmd, args, cb) {
          let scope = args.options.scope;
          let force = args.options.force;
          if (!scope) {
              scope = "web";
          }
          if (!force) {
              force = false;
          }
          if (this.verbose) {
              cmd.log(`Enabling feature '${args.options.featureId}' on scope '${scope}' for url '${args.options.url}' (force='${force}')...`);
          }
          const url = `${args.options.url}/_api/${scope}/features/add(featureId=guid'${args.options.featureId}',force=${force})`;
          const requestOptions = {
              url: url,
              headers: {
                  accept: 'application/json;odata=nometadata'
              }
          };
          request_1.default
              .post(requestOptions)
              .then((res) => {
              if (this.verbose) {
                  cmd.log(vorpal.chalk.green('DONE'));
              }
              cb();
          }, (err) => this.handleRejectedODataJsonPromise(err, cmd, cb));
      }
      types() {
          return {
              string: ['scope', 's']
          };
      }
      options() {
          const options = [
              {
                  option: '-u, --url <url>',
                  description: 'The URL of the site or web for which to enable the feature'
              },
              {
                  option: '-f, --featureId <id>',
                  description: 'The ID of the feature to enable'
              },
              {
                  option: '-s, --scope [scope]',
                  description: 'Scope of the Feature to enable. Allowed values `Site|Web`. Default `Web`',
                  autocomplete: ['Site', 'Web']
              },
              {
                  option: '--force',
                  description: 'Specifies whether to overwrite an existing feature with the same feature identifier. This parameter is ignored if there are no errors.'
              }
          ];
          const parentOptions = super.options();
          return options.concat(parentOptions);
      }
      validate() {
          return (args) => {
              if (!args.options.url) {
                  return 'Required parameter url missing';
              }
              if (!args.options.featureId) {
                  return 'Required parameter featureId missing';
              }
              if (args.options.scope) {
                  if (['site', 'web'].indexOf(args.options.scope.toLowerCase()) < 0) {
                      return `${args.options.scope} is not a valid Feature scope. Allowed values are Site|Web`;
                  }
              }
              return true;
          };
      }
      commandHelp(args, log) {
          const chalk = vorpal.chalk;
          log(vorpal.find(commands_1.default.FEATURE_ENABLE).helpInformation());
          log(`  Remarks:
  
      If the specified ${chalk.grey('url')} doesn't refer to an existing site collection,
      you will get a ${chalk.grey('"404 FILE NOT FOUND"')} error.
        
    Examples:
    
      Enable site feature
        ${this.name} --url https://contoso.sharepoint.com/sites/sales --featureId 915c240e-a6cc-49b8-8b2c-0bff8b553ed3 --scope Site
  
      Enable web feature (with force to overwrite feature with same id)
        ${this.name} --url https://contoso.sharepoint.com/sites/sales --featureId 00bfea71-5932-4f9c-ad71-1557e5751100 --scope Web --force
      `);
      }
  }
  module.exports = new SpoFeatureEnableCommand();
  //# sourceMappingURL=feature-enable.js.map