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

import {Script, console} from "forge-std/Script.sol";
import {Chain138MainnetCheckpoint} from "../../contracts/mainnet-checkpoint/Chain138MainnetCheckpoint.sol";
import {MirrorDetailExtension} from "../../contracts/mainnet-checkpoint/extensions/MirrorDetailExtension.sol";
import {ExtensionIds} from "../../contracts/mainnet-checkpoint/libraries/ExtensionIds.sol";

contract ReplaceMirrorDetailExtension is Script {
    function run() external {
        address proxy = vm.envAddress("CHAIN138_MAINNET_CHECKPOINT_PROXY");
        address oldMirror = vm.envAddress("EXT_MIRROR_DETAIL");
        uint256 pk = vm.envUint("PRIVATE_KEY");

        vm.startBroadcast(pk);
        MirrorDetailExtension mirror = new MirrorDetailExtension();
        console.log("New MirrorDetail:", address(mirror));

        Chain138MainnetCheckpoint hub = Chain138MainnetCheckpoint(proxy);
        hub.setExtensionActive(ExtensionIds.MIRROR_DETAIL, true);
        hub.revokeExtension(ExtensionIds.MIRROR_DETAIL);
        hub.registerExtension(ExtensionIds.MIRROR_DETAIL, address(mirror), mirror.HOOK_AFTER_SUBMIT());
        hub.setExtensionActive(ExtensionIds.MIRROR_DETAIL, true);
        console.log("Replaced mirror (old was):", oldMirror);
        vm.stopBroadcast();
    }
}
