contract Whitelist is Issuable {
  bytes32 public constant WHITELISTED_ROLE = keccak256("WHITELISTED_ROLE");

  bool public whitelistEnabled;

  constructor(bool _enableWhitelist) {
      whitelistEnabled = _enableWhitelist;
  }

  /**
   * @dev Throws if operator is not whitelisted and whitelist is enabled.
   * @param _operator address
   */
  modifier onlyIfWhitelisted(address _operator) {
    if(whitelistEnabled) {
      require(hasRole(WHITELISTED_ROLE, _operator), "Account not whitelisted");
    }
    _;
  }

  function enableWhitelist() public onlyOwner {
    whitelistEnabled = true;
  }

  function disableWhitelist() public onlyOwner {
    whitelistEnabled = false;
  }

  /**
   * @dev add an address to the whitelist
   * @param _operator address
   */
  function addAddressToWhitelist(address _operator) public onlyIssuer {
    grantRole(WHITELISTED_ROLE, _operator);
  }

  /**
   * @dev getter to determine if address is in whitelist
   */
  function whitelist(address _operator) public view returns (bool) {
    return hasRole(WHITELISTED_ROLE, _operator);
  }

  /**
   * @dev add addresses to the whitelist
   * @param _operators addresses
   */
  function addAddressesToWhitelist(address[] memory _operators) public onlyIssuer {
    for (uint256 i = 0; i < _operators.length; i++) {
      addAddressToWhitelist(_operators[i]);
    }
  }

  /**
   * @dev remove an address from the whitelist
   * @param _operator address
   */
  function removeAddressFromWhitelist(address _operator) public onlyIssuer {
    revokeRole(WHITELISTED_ROLE, _operator);
  }

  /**
   * @dev remove addresses from the whitelist
   * @param _operators addresses
   */
  function removeAddressesFromWhitelist(address[] memory _operators) public onlyIssuer {
    for (uint256 i = 0; i < _operators.length; i++) {
      removeAddressFromWhitelist(_operators[i]);
    }
  }

}
/**
 * @title Whitelist
 * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions.
 * This simplifies the implementation of "user permissions".
 By default whitelist in not enabled.
 */
function whitelist(address _operator) public view returns (bool) {
  return hasRole(WHITELISTED_ROLE, _operator);
}

/**
 * @dev getter to determine if address is in whitelist
 */