contract EquipGeneratorWhitelist is Ownable {
  mapping(address => string) public whitelist;
  mapping(string => address)  cat2address;

  event WhitelistedAddressAdded(address addr,string category);
  event WhitelistedAddressRemoved(address addr);

  /**
   * @dev Throws if called by any account that's not whitelisted.
   */
  modifier canGenerate() {
    //require(keccak256(whitelist[msg.sender]) == keccak256(category));
    require(bytes(whitelist[msg.sender]).length >0 );
    _;
  }

  /**
   * @dev add an address to the whitelist
   * @param addr address
   * @return true if the address was added to the whitelist, false if the address was already in the whitelist
   */
  function addAddressToWhitelist(address addr,string memory category) onlyOwner internal returns(bool success) {
    require( bytes(category).length > 0 );
    if (bytes(whitelist[addr]).length == 0) {
      require( cat2address[category] == address(0));
      whitelist[addr] = category;
      emit WhitelistedAddressAdded(addr,category);
      success = true;
    }
  }


  /**
   * @dev remove an address from the whitelist
   * @param addr address
   * @return true if the address was removed from the whitelist,
   * false if the address wasn't in the whitelist in the first place
   */
  function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) {
    string storage category = whitelist[addr];
    if (bytes(category).length != 0) {
      delete cat2address[category] ;
      delete whitelist[addr]  ;
      emit WhitelistedAddressRemoved(addr);
      success = true;
    }
  }



}
/**
 * @title Whitelist
 * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions.
 * @dev This simplifies the implementation of "user permissions".
 */
function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) {
  string storage category = whitelist[addr];
  if (bytes(category).length != 0) {
    delete cat2address[category] ;
    delete whitelist[addr]  ;
    emit WhitelistedAddressRemoved(addr);
    success = true;
  }
}

/**
 * @dev remove an address from the whitelist
 * @param addr address
 * @return true if the address was removed from the whitelist,
 * false if the address wasn't in the whitelist in the first place
 */