<commit_before>'use strict';

var async = require('async');
var utils = require('../utils');

var Account = require('./Account');
var Application = require('./Application');
var CustomData = require('./CustomData');
var IdSiteModel = require('./IdSiteModel');
var OrganizationAccountStoreMapping = require('./OrganizationAccountStoreMapping');

/**
 * @class Organization
 *
 * @description
 *
 * Encapsulates a Organization resource. For full documentation of this resource,
 * please see
 * [REST API Reference: Organization](https://docs.stormpath.com/rest/product-guide/latest/reference.html?#organization).
 *
 * This class should not be manually constructed. It should be obtained from one
 * of these methods:
 *
 * - {@link AccountStoreMapping#getAccountStore AccountStoreMapping.getAccountStore()}
 * - {@link Client#getOrganization Client.getOrganization()}
 * - {@link Client#getOrganizations Client.getOrganizations()}
 * - {@link Directory#getOrganizations Directory.getOrganizations()}
 *
 * @augments {InstanceResource}
 *
 * @param {Object} organizationResource
 *
 * The JSON representation of this resource.
 *
 */
function Organization() {
  Organization.super_.apply(this, arguments);
}

utils.inherits(Organization, require('./InstanceResource'));

/**
 * Creates an {@link Account} in the organization's default account store.
 *
 * @param {AccountData} accountData
 * The data for the new account object.
 *
 * @param {ExpansionOptions} [expansionOptions]
 * For retrieving linked resources of the {@link Account} during this request.
 *
 * @param {Function} callback - Callback function, will be called with (err,
 * {@link Account}).
 *
 * @example
 *
 * var account = {
 *   givenName: 'Foo',
 *   surname: 'Bar',
 *   username: 'foolmeonce',
 *   email: '<EMAIL>',
 *   password: '<PASSWORD>!'
 * };
 *
 * organization.createAccount(account, function(err, createdAccount) {
 *   console.log(createdAccount);
 * });
 */
Organization.prototype.createAccount = function createAccount(/* account, [options,] callback */) {
  var args = utils.resolveArgs(arguments, ['account', 'options', 'callback']);
  return this.dataStore.createResource(this.accounts.href, args.options, args.account, Account, args.callback);
};

/**
 * Creates a group within the default group store of the Organization. If the
 * organization does not have a default group store, this will error.
 *
 * @param {Group} group
 * New group definition.
 *
 * @param {Function} callback
 * The function to call when the operation is complete. Will be called with the
 * parameters (err, {@link Group}).
 *
 * @example
 *
 * var group = {
 *   name: 'New Users'
 * };
 *
 * organization.createGroup(group, function (err, group) {
 *   if (!err) {
 *     console.log('Group Created!');
 *   }
 * });
 */
Organization.prototype.createGroup = function createGroup(/* group, [options,] callback */) {
  var args = utils.resolveArgs(arguments, ['group', 'options', 'callback']);
  return this.dataStore.createResource(this.groups.href, args.options, args.group, require('./Group'), args.callback);
};

/**
 *
 * Use this method to get an account from a provider directory.  This method is
 * the same as {@link Application#getAccount Application.getAccount()}, but
 * will be scoped to the account stores that are mapped to this Organization.
 *
 * @param {Object} providerAccountRequest See {@link Application#getAccount Application.getAccount()}.
 *
 * @param {Function} callback
 * Callback function to call with parameters (`err`, {@link ProviderAccountResult}).
 *
 * @example
 *
 * var providerAccountRequest = {
 *   providerData: {
 *     providerId: 'facebook',
 *     accessToken: 'abc1235'
 *   }
 * };
 *
 * organization.getAccount(providerAccountRequest, function(err, providerAccountResult) {
 *   if (providerAccountResult.created) {
 *     console.log('This user was newly created in the directory.');
 *   }
 *
 *   console.log(providerAccountResult.account);
 * });
 */
Organization.prototype.getAccount = function(){
  Application.prototype.getAccount.apply(this, arguments);
};

/**
 * Get the account's collection for this Organization, which is a list of all
 * accounts in all account stores that are mapped to this organization.
 *
 * @param {CollectionQueryOptions} collectionQueryOptions
 * Options for querying, paginating, and expanding the collection. This collection
 * supports filter searches and the following attribute searches:
 * `createdAt`, `email`, `givenName`, `middleName`, `modifiedAt`, `surname`,
 * `status`, `username`.
 *
 * @param {Function} callback
 * The function to call when the operation is complete. Will be called
 * with the parameters (err, {@link CollectionResource}). The collection will
 * be a list of {@link Account} objects.
 *
 * @example<commit_msg>minor cleanup<commit_after>'use strict';

var async = require('async');
var utils = require('../utils');

var Account = require('./Account');
var Application = require('./Application');
var CustomData = require('./CustomData');
var IdSiteModel = require('./IdSiteModel');
var OrganizationAccountStoreMapping = require('./OrganizationAccountStoreMapping');

/**
 * @class Organization
 *
 * @description
 *
 * Encapsulates a Organization resource. For full documentation of this resource,
 * please see
 * [REST API Reference: Organization](https://docs.stormpath.com/rest/product-guide/latest/reference.html?#organization).
 *
 * This class should not be manually constructed. It should be obtained from one
 * of these methods:
 *
 * - {@link AccountStoreMapping#getAccountStore AccountStoreMapping.getAccountStore()}
 * - {@link Client#getOrganization Client.getOrganization()}
 * - {@link Client#getOrganizations Client.getOrganizations()}
 * - {@link Directory#getOrganizations Directory.getOrganizations()}
 *
 * @augments {InstanceResource}
 *
 * @param {Object} organizationResource
 *
 * The JSON representation of this resource.
 *
 */
function Organization() {
  Organization.super_.apply(this, arguments);
}

utils.inherits(Organization, require('./InstanceResource'));

/**
 * Creates an {@link Account} in the organization's default account store.
 *
 * @param {AccountData} accountData
 * The data for the new account object.
 *
 * @param {ExpansionOptions} [expansionOptions]
 * For retrieving linked resources of the {@link Account} during this request.
 *
 * @param {Function} callback - Callback function, will be called with (err,
 * {@link Account}).
 *
 * @example
 *
 * var account = {
 *   givenName: 'Foo',
 *   surname: 'Bar',
 *   username: 'foolmeonce',
 *   email: '<EMAIL>',
 *   password: '<PASSWORD>!'
 * };
 *
 * organization.createAccount(account, function(err, createdAccount) {
 *   console.log(createdAccount);
 * });
 */
Organization.prototype.createAccount = function createAccount(/* account, [options,] callback */) {
  var args = utils.resolveArgs(arguments, ['account', 'options', 'callback']);
  return this.dataStore.createResource(this.accounts.href, args.options, args.account, Account, args.callback);
};

/**
 * Creates a group within the default group store of the Organization. If the
 * organization does not have a default group store, this will error.
 *
 * @param {Group} group
 * New group definition.
 *
 * @param {Function} callback
 * The function to call when the operation is complete. Will be called with the
 * parameters (err, {@link Group}).
 *
 * @example
 *
 * var group = {
 *   name: 'New Users'
 * };
 *
 * organization.createGroup(group, function (err, group) {
 *   if (!err) {
 *     console.log('Group Created!');
 *   }
 * });
 */
Organization.prototype.createGroup = function createGroup(/* group, [options,] callback */) {
  var args = utils.resolveArgs(arguments, ['group', 'options', 'callback']);
  return this.dataStore.createResource(this.groups.href, args.options, args.group, require('./Group'), args.callback);
};

/**
 * Use this method to get an account from a provider directory. This method is
 * the same as {@link Application#getAccount Application.getAccount()} but
 * will be scoped to the account stores that are mapped to this Organization.
 *
 * @param {Object} providerAccountRequest
 * See {@link Application#getAccount Application.getAccount()}.
 *
 * @param {Function} callback
 * Callback function to call with parameters (`err`, {@link ProviderAccountResult}).
 *
 * @example
 *
 * var providerAccountRequest = {
 *   providerData: {
 *     providerId: 'facebook',
 *     accessToken: 'abc1235'
 *   }
 * };
 *
 * organization.getAccount(providerAccountRequest, function(err, providerAccountResult) {
 *   if (providerAccountResult.created) {
 *     console.log('This user was newly created in the directory.');
 *   }
 *
 *   console.log(providerAccountResult.account);
 * });
 */
Organization.prototype.getAccount = function () {
  Application.prototype.getAccount.apply(this, arguments);
};

/**
 * Get the account's collection for this Organization, which is a list of all
 * accounts in all account stores that are mapped to this organization.
 *
 * @param {CollectionQueryOptions} collectionQueryOptions
 * Options for querying, paginating, and expanding the collection. This collection
 * supports filter searches and the following attribute searches:
 * `createdAt`, `email`, `givenName`, `middleName`, `modifiedAt`, `surname`,
 * `status`, `username`.
 *
 * @param {Function} callback
 * The function to call when the operation is complete. Will be called
 * with the parameters (err, {@link CollectionResource}). The collection will
 * be a list of {@link Account} objects.
 *
 * @example
{'fraction_non_alphanumeric': 0.13242342154615544, 'fraction_numerical': 0.0008335069806209627, 'mean_word_length': 4.526194588370754, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6932225', 'n_tokens_mistral': 2568, 'n_tokens_neox': 2551, 'n_words': 830}