// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// TEST-ONLY sink whose flush(token, amount) can be toggled to revert. Lets a test drive
/// AERE402FacilitatorPQC down its best-effort "sink flush failed" branch (which accrues a
/// tracked fee residual) and then recover the sink to prove flushResidual forwards ONLY that
/// residual. Mirrors MockSinkSimple's pull-on-flush behavior when not failing. Not for prod.
contract MockSinkToggle {
    bool public fail;
    uint256 public lastFlushAmount;
    event Flushed(address token, uint256 amount);

    function setFail(bool v) external {
        fail = v;
    }

    function flush(address token, uint256 amount) external {
        require(!fail, "sink-down");
        require(IERC20(token).transferFrom(msg.sender, address(this), amount), "transfer-failed");
        lastFlushAmount = amount;
        emit Flushed(token, amount);
    }
}
