contract PineappleArcadeTrophy is ERC721Token, Pausable {
    /// @notice Name and Symbol are part of the ERC721 standard
    string public constant name = "PineappleArcadeTrophy";
    string public constant symbol = "DEGEN";

    Marketplace public marketplace;
    uint256 public maxTrophies;

    /// @dev trophyId to trophyName
    mapping (uint256 => bytes32) public trophies;

    function PineappleArcadeTrophy(uint256 _maxTrophies) public {
        maxTrophies = _maxTrophies;
        pause();
    }

    function setMarketplace(Marketplace _marketplace) external onlyOwner {
        marketplace = _marketplace;
    }

    function grantTrophy(address _initialOwner, bytes32 _trophyName) external onlyOwner {
        require(totalSupply() < maxTrophies);
        require(_trophyName != 0x0);
        trophies[nextId()] = _trophyName;
        _mint(_initialOwner, nextId());
    }

    function listTrophy(uint256 _trophyId, uint256 _startingPriceWei, uint256 _minimumPriceWei, uint256 _durationSeconds) external whenNotPaused {
        address _trophySeller = ownerOf(_trophyId);
        require(_trophySeller == msg.sender);
        approve(marketplace, _trophyId);
        marketplace.list(_trophySeller, _trophyId, _startingPriceWei, _minimumPriceWei, _durationSeconds);
    }

    function unlistTrophy(uint256 _trophyId) external {
        marketplace.unlist(msg.sender, _trophyId);
    }

    function currentPrice(uint256 _trophyId) public view returns(uint256) {
        return marketplace.currentPrice(_trophyId);
    }

    function purchaseTrophy(uint256 _trophyId) external payable whenNotPaused {
        // Blockade collects 3.75% of each market transaction, paid by the seller.
        uint256 _blockadeFee = (msg.value * 375) / 10000; // Note: small values prevent Blockade from earning anything
        uint256 _sellerTake = msg.value - _blockadeFee;
        marketplace.purchase.value(_sellerTake)(msg.sender, _trophyId, msg.value);
    }

    /// @notice With each call to purchaseTrophy, fees will build up in this contract's balance.
    /// This method allows the contract owner to transfer that balance to their account.
    function withdrawBalance() external onlyOwner {
        owner.transfer(this.balance);
    }

    function nextId() internal view returns (uint256) {
        return totalSupply() + 1;
    }
}
function withdrawBalance() external onlyOwner {
    owner.transfer(this.balance);
}

/// @notice With each call to purchaseTrophy, fees will build up in this contract's balance.
/// This method allows the contract owner to transfer that balance to their account.