var minChar = 'abcdefghijklmnopqrstuvwxyz';
var majChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var numChar = '0123456789';
var symChar = '!@#$%^&*()+_-=}{[]|:;"/?.><,`~';

var shuffle = require('../string/shuffle');

/**
 * Generate a password
 *
 * @param {number} [length = 5] Password length
 * @param {boolean} [lowercase = true] If password contain lowercases
 * @param {boolean} [uppercase = true] If password contain uppercases
 * @param {boolean} [numbers = true] If password contain numbers
 * @param {boolean} [symbols = false] If password contain symbols
 * @return {string} Password
 *
 * @example
 * var snu = require('s-node-utils');
 *
 * snu.password.generate(50, true, true, false, true);
 * //=> Hnn}VnDySrnlJU.US>}vt<]|@)I^CB/.}|ehxFV_w%f;m,AlJA
 */
module.exports = function(
  length = 5,
  lowercase = true,
  uppercase = true,
  numbers = true,
  symbols = false
) {
  var map, finalmap, password, final;

  if (lowercase === true) {
    map += minChar;
  }
  if (uppercase === true) {
    map += majChar;
  }
  if (numbers === true) {
    map += numChar;
  }
  if (symbols === true) {
    map += symChar;
  }

  finalmap = map.replace('undefined', '');

  for (var i = 0; i < length; i++) {
    password += finalmap.charAt(Math.floor(Math.random() * finalmap.length));
  }

  final = password.replace('undefined', '');

  return shuffle(final);
};
