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

import "forge-std/Test.sol";
import { PartnershipBondV3Safe } from "../../contracts/bonds/PartnershipBondV3Safe.sol";
import { ThresholdConsensusV3 } from "../../contracts/consensus/ThresholdConsensusV3.sol";
import { DisputeRegistryV3 } from "../../contracts/disputes/DisputeRegistryV3.sol";

/// @notice Invariant #15 — self-bonds are rejected at createBond.
///         This is a structural test: with partyA == partyB, createBond must
///         revert with SelfBondForbidden before any signature check.
contract Inv15_NoSelfBonds is Test {
    PartnershipBondV3Safe internal bonds;
    address internal owner = address(0xBEEF);
    address internal alice = address(0xA11CE);
    ThresholdConsensusV3 internal consensus;
    DisputeRegistryV3 internal disputes;

    function setUp() public {
        consensus = new ThresholdConsensusV3(owner, 2);
        disputes = new DisputeRegistryV3(owner);
        bonds = new PartnershipBondV3Safe(
            owner, address(0), address(consensus), address(disputes), 10 ether, 20 ether, 100 ether, address(0)
        );
    }

    function test_self_bond_rejected() external {
        PartnershipBondV3Safe.Terms memory t = PartnershipBondV3Safe.Terms({
            bondId: 1,
            partyA: alice,
            partyB: alice, // self
            partyAStake: 1 ether,
            partyBStake: 1 ether,
            stakeAsset: address(0),
            partnershipType: bytes32("test"),
            breachConditionsHash: bytes32(0),
            objectiveRuleClass: 1,
            objectiveRuleSchemaVersion: 1,
            flourishRewardConditionsHash: bytes32(0),
            rewardProgramId: 0,
            proposalDeadline: uint64(block.timestamp + 1 days),
            activePeriodStart: uint64(block.timestamp + 2 days),
            activePeriodEnd: uint64(block.timestamp + 30 days),
            challengeWindow: 3 days,
            nonce: 1,
            chainId: block.chainid,
            protocolVersion: "3.0.0"
        });
        vm.expectRevert(PartnershipBondV3Safe.SelfBondForbidden.selector);
        bonds.createBond(t, hex"", hex"");
    }
}
