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

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

/// @title Inv03_MutualConsent
/// @notice PartnershipBondV3Safe.createBond requires both parties' EIP-712 signatures with matching fields.
contract Inv03_MutualConsent is V3Fixtures {
    PartnershipBondV3Safe internal bonds;

    function setUp() public {
        _setUpDependencies();
        bonds = new PartnershipBondV3Safe(
            owner, address(0), address(consensus), address(disputeRegistry), 10 ether, 20 ether, 100 ether, address(0)
        );
    }

    function test_matching_signatures_from_both_parties_create_bond() external {
        PartnershipBondV3Safe.Terms memory terms = _partnershipTerms(3, 1 ether, 1 ether);

        uint256 bondId = bonds.createBond(
            terms, _signPartnership(bonds, terms, PARTY_A_KEY), _signPartnership(bonds, terms, PARTY_B_KEY)
        );

        PartnershipBondV3Safe.BondData memory created = bonds.bondOf(bondId);
        assertEq(created.terms.partyA, partyA);
        assertEq(created.terms.partyB, partyB);
        assertEq(created.terms.nonce, terms.nonce);
    }

    function test_signature_for_different_terms_cannot_supply_mutual_consent() external {
        PartnershipBondV3Safe.Terms memory signedTerms = _partnershipTerms(4, 1 ether, 1 ether);
        bytes memory sigA = _signPartnership(bonds, signedTerms, PARTY_A_KEY);
        bytes memory sigB = _signPartnership(bonds, signedTerms, PARTY_B_KEY);

        PartnershipBondV3Safe.Terms memory changedTerms = signedTerms;
        changedTerms.partyBStake = 2 ether;
        vm.expectRevert(PartnershipBondV3Safe.BadSignature.selector);
        bonds.createBond(changedTerms, sigA, sigB);
    }
}
