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

import "forge-std/Test.sol";
import "../../contracts/rwa/RWAToken.sol";
import "../../contracts/rwa/GruMonetaryPolicyGate.sol";
import "../../contracts/rwa/IGruMonetaryPolicyGate.sol";

contract GruMonetaryPolicyGateTest is Test {
    GruMonetaryPolicyGate gate;
    RWAToken liToken;
    address admin = address(0xA11CE);

    function setUp() public {
        vm.startPrank(admin);
        gate = new GruMonetaryPolicyGate(admin, 12000, 11800, 25);
        liToken = new RWAToken(
            "LiXAU Test",
            "LiXAU",
            6,
            "LiXAU",
            "Commodities",
            "Gold",
            "Index",
            "XAU",
            "M00",
            admin,
            admin,
            admin,
            1_000_000,
            0,
            keccak256("methodology-test")
        );
        gate.setTokenGate(address(liToken), true);
        liToken.setPolicyGate(address(gate));
        vm.stopPrank();
    }

    function test_AllowsMintWhenGreen() public {
        vm.prank(admin);
        gate.updateMetrics(15000, 10, IGruMonetaryPolicyGate.VelocityZone.Green, false);
        vm.prank(admin);
        liToken.mint(admin, 1000e6);
        assertEq(liToken.totalSupply(), 1000e6);
    }

    function test_BlocksMintOnCoverageAlert() public {
        vm.prank(admin);
        gate.updateMetrics(11700, 10, IGruMonetaryPolicyGate.VelocityZone.Green, false);
        vm.prank(admin);
        vm.expectRevert("RWAToken: policy gate");
        liToken.mint(admin, 1000e6);
    }

    function test_BlocksMintOnUtilization() public {
        vm.prank(admin);
        gate.updateMetrics(15000, 30, IGruMonetaryPolicyGate.VelocityZone.Green, false);
        vm.prank(admin);
        vm.expectRevert("RWAToken: policy gate");
        liToken.mint(admin, 1000e6);
    }

    function test_SkipGateWhenTokenNotEnabled() public {
        vm.prank(admin);
        gate.setTokenGate(address(liToken), false);
        vm.prank(admin);
        gate.updateMetrics(10000, 99, IGruMonetaryPolicyGate.VelocityZone.Red, true);
        vm.prank(admin);
        liToken.mint(admin, 1000e6);
        assertEq(liToken.totalSupply(), 1000e6);
    }
}
