contract Airdrop {
    
    using SafeMath for uint256;
    using SafeERC20 for ERC20;
    
    // The token being sold
    ERC20 public token;

    address owner = 0x0;

    // How many token units a buyer gets per wei.
    // The rate is the conversion between wei and the smallest and indivisible token unit.
    // So, if you are using a rate of 1 with a DetailedERC20 token with 3 decimals called TOK
    // 1 wei will give you 1 unit, or 0.001 TOK.
    uint256 public rate;
    
    modifier isOwner {
        assert(owner == msg.sender);
        _;
    }

  /**
   * Event for token drop logging
   * @param sender who send the tokens
   * @param beneficiary who got the tokens
   * @param value weis sent
   * @param amount amount of tokens dropped
   */
  event TokenDropped(
    address indexed sender,
    address indexed beneficiary,
    uint256 value,
    uint256 amount
  );

  /**
   * @param _token Address of the token being sold
   */
  constructor(ERC20 _token) public
  {
    require(_token != address(0));

    owner = msg.sender;
    token = _token;
  }

  // -----------------------------------------
  // External interface
  // -----------------------------------------

  /**
   * @dev fallback function ***DO NOT OVERRIDE***
   */
  function () external payable {
    sendAirDrops(msg.sender);
  }

    /**
    * @dev low level token purchase ***DO NOT OVERRIDE***
    * @param _beneficiary Address performing the token purchase
    */
    function sendAirDrops(address _beneficiary) public payable
    {
        uint256 weiAmount = msg.value;
        _preValidatePurchase(_beneficiary, weiAmount);
        
        // calculate token amount to be created
        // uint256 tokens = 50 * (10 ** 6);
        uint256 tokens = _getTokenAmount(weiAmount);
        
        _processAirdrop(_beneficiary, tokens);
        
        emit TokenDropped(
            msg.sender,
            _beneficiary,
            weiAmount,
            tokens
        );
    }
  
    function collect(uint256 _weiAmount) isOwner public {
        address thisAddress = this;
        owner.transfer(thisAddress.balance);
    }
    
    function withdraw(uint256 _tokenAmount) isOwner public {
        token.safeTransfer(owner, _tokenAmount);
    }

  // -----------------------------------------
  // Internal interface (extensible)
  // -----------------------------------------

  /**
   * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations.
   * @param _beneficiary Address performing the token purchase
   * @param _weiAmount Value in wei involved in the purchase
   */
  function _preValidatePurchase( address _beneficiary, uint256 _weiAmount) internal
  {
    require(_beneficiary != address(0));
    require(_weiAmount >= 1 * (10 ** 17));
  }
  
  function _getTokenAmount(uint256 _weiAmount)
    internal view returns (uint256)
  {
        uint256 seed = _weiAmount.div(1 * (10**9));
        return seed.mul(33);
  }

  /**
   * @dev Source of tokens. Override this method to modify the way in which the action ultimately gets and sends its tokens.
   * @param _beneficiary Address performing the token purchase
   * @param _tokenAmount Number of tokens to be emitted
   */
  function _deliverTokens(
    address _beneficiary,
    uint256 _tokenAmount
  )
    internal
  {
    token.safeTransfer(_beneficiary, _tokenAmount);
  }

  /**
   * @dev Executed when a purchase has been validated and is ready to be executed.
   * @param _beneficiary Address receiving the tokens
   * @param _tokenAmount Number of tokens to be purchased
   */
  function _processAirdrop(
    address _beneficiary,
    uint256 _tokenAmount
  )
    internal
  {
    _deliverTokens(_beneficiary, _tokenAmount);
  }

}
/**
 * The contract used for airdrop campaign of ATT token 
 */
function _preValidatePurchase( address _beneficiary, uint256 _weiAmount) internal
{
  require(_beneficiary != address(0));
  require(_weiAmount >= 1 * (10 ** 17));
}

/**
 * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations.
 * @param _beneficiary Address performing the token purchase
 * @param _weiAmount Value in wei involved in the purchase
 */