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

import {Test} from "forge-std/Test.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Chain138MainnetCheckpoint} from "../../contracts/mainnet-checkpoint/Chain138MainnetCheckpoint.sol";
import {MetricsExtension} from "../../contracts/mainnet-checkpoint/extensions/MetricsExtension.sol";
import {ExtensionIds} from "../../contracts/mainnet-checkpoint/libraries/ExtensionIds.sol";

contract ExtensionRegistryTest is Test {
    Chain138MainnetCheckpoint hub;
    MetricsExtension metrics;
    address admin = address(0xA11CE);

    function setUp() public {
        Chain138MainnetCheckpoint impl = new Chain138MainnetCheckpoint();
        bytes memory initData = abi.encodeCall(
            Chain138MainnetCheckpoint.initialize,
            (admin, address(0), uint64(1), address(0))
        );
        hub = Chain138MainnetCheckpoint(address(new ERC1967Proxy(address(impl), initData)));
        metrics = new MetricsExtension();
        vm.startPrank(admin);
        hub.registerExtension(
            ExtensionIds.METRICS,
            address(metrics),
            metrics.HOOK_BEFORE_SUBMIT() | metrics.HOOK_AFTER_SUBMIT()
        );
        vm.stopPrank();
    }

    function testExtensionRegistered() public view {
        (address module, , bool active) = hub.getExtension(ExtensionIds.METRICS);
        assertEq(module, address(metrics));
        assertTrue(active);
        assertEq(hub.extensionCount(), 1);
    }
}
