contract BidoohToken is MintableToken {
    string public constant name = "Bidooh Token2";
    string public constant symbol = "DOOH2";
    uint8 public constant decimals = 18;

    /// This address is be assigned the Bidooh Team tokens
    address public teamTokensAddress;

    /// This address is be assigned the Reserve tokens
    address public reserveTokensAddress;

    /// This address is be assigned the Sale tokens
    address public saleTokensAddress;

    /// This address will have the sole ability to mint more tokens
    address public bidoohAdminAddress;

    /// a safeguard flag to prevent multiple calls of close()
    bool public saleClosed = false;

    /// Only allowed to execute before the token sale is closed
    modifier beforeSaleClosed {
        require(!saleClosed);
        _;
    }

    constructor(address _teamTokensAddress, address _reserveTokensAddress,
                address _saleTokensAddress, address _bidoohAdminAddress) public {
        require(_teamTokensAddress != address(0));
        require(_reserveTokensAddress != address(0));
        require(_saleTokensAddress != address(0));
        require(_bidoohAdminAddress != address(0));

        teamTokensAddress = _teamTokensAddress;
        reserveTokensAddress = _reserveTokensAddress;
        saleTokensAddress = _saleTokensAddress;
        bidoohAdminAddress = _bidoohAdminAddress;

        /// Maximum tokens to be allocated on the sale
        /// 88.2 billion DOOH
        uint256 saleTokens = 88200000000 * 10**uint256(decimals);
        totalSupply_ = saleTokens;
        balances[saleTokensAddress] = saleTokens;

        /// Reserve tokens - 18.9 billion DOOH
        uint256 reserveTokens = 18900000000 * 10**uint256(decimals);
        totalSupply_ = totalSupply_.add(reserveTokens);
        balances[reserveTokensAddress] = reserveTokens;

        /// Team tokens - 18.9 billion DOOH
        uint256 teamTokens = 18900000000 * 10**uint256(decimals);
        totalSupply_ = totalSupply_.add(teamTokens);
        balances[teamTokensAddress] = teamTokens;
    }

    /// @dev Close the token sale and transfer ownership
    function close() public onlyOwner beforeSaleClosed {
        uint256 unsoldTokens = balances[saleTokensAddress];
        balances[reserveTokensAddress] = balances[reserveTokensAddress].add(unsoldTokens);
        balances[saleTokensAddress] = 0;
        emit Transfer(saleTokensAddress, reserveTokensAddress, unsoldTokens);

        owner = bidoohAdminAddress;
        saleClosed = true;
    }
}
function close() public onlyOwner beforeSaleClosed {
    uint256 unsoldTokens = balances[saleTokensAddress];
    balances[reserveTokensAddress] = balances[reserveTokensAddress].add(unsoldTokens);
    balances[saleTokensAddress] = 0;
    emit Transfer(saleTokensAddress, reserveTokensAddress, unsoldTokens);

    owner = bidoohAdminAddress;
    saleClosed = true;
}

/// @dev Close the token sale and transfer ownership