// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import "../../contracts/iso4217w/ComplianceGuard.sol";

contract ComplianceGuardTest is Test {
    ComplianceGuard public guard;

    address public admin = address(0x1);

    function setUp() public {
        guard = new ComplianceGuard(admin);
    }

    function test_ValidateMoneyMultiplier() public {
        // Reserve >= Supply (m = 1.0 or better)
        assertTrue(guard.validateMoneyMultiplier(1000, 1000)); // m = 1.0
        assertTrue(guard.validateMoneyMultiplier(1100, 1000)); // m = 1.1

        // Reserve < Supply (m < 1.0) - should fail
        assertFalse(guard.validateMoneyMultiplier(900, 1000)); // m = 0.9
    }

    function test_IsISO4217Compliant() public {
        assertTrue(guard.isISO4217Compliant("USD"));
        assertTrue(guard.isISO4217Compliant("EUR"));
        assertTrue(guard.isISO4217Compliant("GBP"));

        // GRU isolation
        assertFalse(guard.isISO4217Compliant("GRU"));
        assertFalse(guard.isISO4217Compliant("M00"));
        assertFalse(guard.isISO4217Compliant("M0"));
        assertFalse(guard.isISO4217Compliant("M1"));
    }

    function test_ViolatesGRUIsolation() public {
        assertTrue(guard.violatesGRUIsolation("GRU"));
        assertTrue(guard.violatesGRUIsolation("M00"));
        assertTrue(guard.violatesGRUIsolation("M0"));
        assertTrue(guard.violatesGRUIsolation("M1"));

        assertFalse(guard.violatesGRUIsolation("USD"));
        assertFalse(guard.violatesGRUIsolation("EUR"));
    }

    function test_ValidateMint() public {
        // Valid mint
        (bool isValid, bytes32 reason) = guard.validateMint("USD", 1000e2, 5000e2, 10000e2);
        assertTrue(isValid);
        assertEq(reason, bytes32(0));

        // Invalid: GRU isolation violation
        (isValid, reason) = guard.validateMint("GRU", 1000e2, 5000e2, 10000e2);
        assertFalse(isValid);
        assertEq(reason, keccak256("GRU_ISOLATION_VIOLATION"));

        // Invalid: Reserve insufficient
        (isValid, reason) = guard.validateMint("USD", 1000e2, 5000e2, 5000e2);
        assertFalse(isValid);
        assertEq(reason, keccak256("RESERVE_INSUFFICIENT_FOR_MINT"));
    }

    function test_IsReserveSufficient() public {
        assertTrue(guard.isReserveSufficient(1000, 1000));
        assertTrue(guard.isReserveSufficient(1100, 1000));
        assertFalse(guard.isReserveSufficient(900, 1000));
    }
}
