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 SpoHubSiteRegisterCommand extends SpoCommand_1.default {
      get name() {
          return `${commands_1.default.HUBSITE_REGISTER}`;
      }
      get description() {
          return 'Registers the specified site collection as a hub site';
      }
      commandAction(cmd, args, cb) {
          this
              .getRequestDigest(args.options.url)
              .then((res) => {
              const requestOptions = {
                  url: `${args.options.url}/_api/site/RegisterHubSite`,
                  headers: {
                      'X-RequestDigest': res.FormDigestValue,
                      accept: 'application/json;odata=nometadata'
                  },
                  json: true
              };
              return request_1.default.post(requestOptions);
          })
              .then((res) => {
              cmd.log(res);
              if (this.verbose) {
                  cmd.log(vorpal.chalk.green('DONE'));
              }
              cb();
          }, (err) => this.handleRejectedODataJsonPromise(err, cmd, cb));
      }
      options() {
          const options = [
              {
                  option: '-u, --url <url>',
                  description: 'URL of the site collection to register as a hub site'
              }
          ];
          const parentOptions = super.options();
          return options.concat(parentOptions);
      }
      validate() {
          return (args) => {
              if (!args.options.url) {
                  return 'Required parameter url missing';
              }
              const isValidSharePointUrl = SpoCommand_1.default.isValidSharePointUrl(args.options.url);
              if (isValidSharePointUrl !== true) {
                  return isValidSharePointUrl;
              }
              return true;
          };
      }
      commandHelp(args, log) {
          const chalk = vorpal.chalk;
          log(vorpal.find(this.name).helpInformation());
          log(`  Remarks:
  
      ${chalk.yellow('Attention:')} This command is based on a SharePoint API that is currently
      in preview and is subject to change once the API reached general
      availability.
  
      If the specified site collection is already registered as a hub site,
      you will get a ${chalk.grey('This site is already a HubSite.')} error.
  
    Examples:
    
      Register the site collection with URL
      ${chalk.grey('https://contoso.sharepoint.com/sites/sales')} as a hub site
        ${this.name} --url https://contoso.sharepoint.com/sites/sales
  
    More information:
  
      SharePoint hub sites new in Office 365
        https://techcommunity.microsoft.com/t5/SharePoint-Blog/SharePoint-hub-sites-new-in-Office-365/ba-p/109547
  `);
      }
  }
  module.exports = new SpoHubSiteRegisterCommand();
  //# sourceMappingURL=hubsite-register.js.map