contract ArtworkAuction is ArtworkLicensing {

    // @notice The auction contract variables are defined in ArtworkBase to allow
    //  us to refer to them in ArtworkOwnership to prevent accidental transfers.
    // `saleAuction` refers to the auction for gen0 and p2p sale of kitties.
    // `siringAuction` refers to the auction for siring rights of kitties.

    /// @dev Sets the reference to the sale auction.
    /// @param _address - Address of sale contract.
    function setSaleAuctionAddress(address _address) external onlyCEO {
        SaleClockAuction candidateContract = SaleClockAuction(_address);

        // NOTE: verify that a contract is what we expect -
        require(candidateContract.isSaleClockAuction());

        // Set the new contract address
        saleAuction = candidateContract;
    }

        /// @dev Sets the reference to the coupling auction.
    /// @param _address - Address of coupling contract.
    function setCouplingAuctionAddress(address _address) external onlyCEO {
        CouplingClockAuction candidateContract = CouplingClockAuction(_address);

        // NOTE: verify that a contract is what we expect -
        require(candidateContract.isCouplingClockAuction());

        // Set the new contract address
        couplingAuction = candidateContract;
    }
        /// @dev Put a artwork up for auction to be coupled.
    ///  delegates to reverse auction.
        function createCouplingAuction(
        uint256 _artworkId,
        uint256 _startingPrice,
        uint256 _endingPrice,
        uint256 _duration
    )
        external
        whenNotPaused
    {
        // Auction contract checks input sizes
        // If artwork is already on any auction, this will throw
        // because it will be owned by the auction contract.
        require(_owns(msg.sender, _artworkId));
        _approve(_artworkId, couplingAuction);
        // Coupling auction throws if inputs are invalid and clears
        // transfer and sire approval after escrowing the artwork.
        couplingAuction.createAuction(
            _artworkId,
            _startingPrice,
            _endingPrice,
            _duration,
            msg.sender
        );
    }
    /// @dev Sets the reference to the siring auction.
        // FIXME ? removed for now

    /// @dev Put an artwork up for auction.
    ///  Does some ownership trickery to create auctions in one tx.
    function createSaleAuction(
        uint256 _artworkId,
        uint256 _startingPrice,
        uint256 _endingPrice,
        uint256 _duration
    )
        external
        whenNotPaused
    {
        // Auction contract checks input sizes
        // If artwork is already on any auction, this will throw
        // because it will be owned by the auction contract.
        require(_owns(msg.sender, _artworkId));
        // Ensure the artwork is not pregnant to prevent the auction
        // contract accidentally receiving ownership of the child.
        // NOTE: the artwork IS allowed to be in a cooldown.
        _approve(_artworkId, saleAuction);
        // Sale auction throws if inputs are invalid and clears
        // transfer and sire approval after escrowing the artwork.
        saleAuction.createAuction(
            _artworkId,
            _startingPrice,
            _endingPrice,
            _duration,
            msg.sender
        );
    }



        /// @dev Completes a coupling auction by bidding.
    ///  Immediately couples the winning top with the bottom on auction.
    /// @param _partnerId - ID of the bottom on auction.
    /// @param _topId - ID of the artwork owned by the bidder.
    function bidOnCouplingAuction(
        uint256 _partnerId,
        uint256 _topId
    )
        external
        payable
        whenNotPaused
    {
        // Auction contract checks input sizes
        require(_owns(msg.sender, _topId));

        // Define the current price of the auction.
        uint256 currentPrice = couplingAuction.getCurrentPrice(_partnerId);
        require(msg.value >= currentPrice);

        // Coupling auction will throw if the bid fails.
        couplingAuction.bid.value(msg.value)(_partnerId);
        _assignLeftpiece(_topId,_partnerId);
    }
   

    /// @dev Transfers the balance of the sale auction contract
    /// to the ArtworkCore contract. We use two-step withdrawal to
    /// prevent two transfer calls in the auction bid function.
    function withdrawAuctionBalances() external onlyCLevel {
        saleAuction.withdrawBalance();
        couplingAuction.withdrawBalance();
    }
}
function bidOnCouplingAuction(
    uint256 _partnerId,
    uint256 _topId
)
    external
    payable
    whenNotPaused
{
    // Auction contract checks input sizes
    require(_owns(msg.sender, _topId));

    // Define the current price of the auction.
    uint256 currentPrice = couplingAuction.getCurrentPrice(_partnerId);
    require(msg.value >= currentPrice);

    // Coupling auction will throw if the bid fails.
    couplingAuction.bid.value(msg.value)(_partnerId);
    _assignLeftpiece(_topId,_partnerId);
}

/// @dev Completes a coupling auction by bidding.
///  Immediately couples the winning top with the bottom on auction.
/// @param _partnerId - ID of the bottom on auction.
/// @param _topId - ID of the artwork owned by the bidder.