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

import { PartnershipBondV3Safe } from "../../contracts/bonds/PartnershipBondV3Safe.sol";
import { MultisigGovernanceV3 } from "../../contracts/governance/MultisigGovernanceV3.sol";
import { V3Fixtures } from "../helpers/V3Fixtures.sol";

/// @title Inv07_GovCannotWithdrawPending
/// @notice MultisigGovernanceV3 cannot move funds from a bond not in TerminalSettled or TerminalCancelled.
contract Inv07_GovCannotWithdrawPending is V3Fixtures {
    MultisigGovernanceV3 internal governance;
    PartnershipBondV3Safe internal bonds;
    address internal signerA = address(0x51A);
    address internal signerB = address(0x51B);
    address internal recipient = address(0xCAFE);
    uint256 internal bondId;

    function setUp() public {
        _setUpDependencies();
        address[] memory signers = new address[](2);
        signers[0] = signerA;
        signers[1] = signerB;
        address[] memory noPauseTargets = new address[](0);
        governance = new MultisigGovernanceV3(
            signers, 2, 1 days, 1 days, address(0x6AADD), 1 days, noPauseTargets, new address[](0), new bytes32[](0)
        );
        bonds = new PartnershipBondV3Safe(
            address(governance),
            address(0),
            address(consensus),
            address(disputeRegistry),
            10 ether,
            20 ether,
            100 ether,
            address(0)
        );
        bondId = _createPartnership(bonds, _partnershipTerms(7, 1 ether, 1 ether));
        _fundActivePartnership(bonds, bondId, 1 ether, 1 ether);
    }

    function test_multisig_cannot_skim_pending_bond_principal() external {
        bytes memory call = abi.encodeCall(PartnershipBondV3Safe.skimSurplus, (address(0), recipient, 1 ether));
        vm.expectPartialRevert(MultisigGovernanceV3.PolicyDenied.selector);
        vm.prank(signerA);
        governance.propose(address(bonds), 0, call);

        assertEq(address(bonds).balance, 2 ether, "pending principal left bond custody");
        assertEq(bonds.nativeLiability(), 2 ether, "pending principal was no longer reserved");
        assertEq(recipient.balance, 0, "governance received pending principal");
    }
}
