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

import {Script, console} from "forge-std/Script.sol";
import {MirrorDetailExtension} from "../../contracts/mainnet-checkpoint/extensions/MirrorDetailExtension.sol";
import {ValidatorSigVerifierExtension} from "../../contracts/mainnet-checkpoint/extensions/ValidatorSigVerifierExtension.sol";
import {AttestationURIExtension} from "../../contracts/mainnet-checkpoint/extensions/AttestationURIExtension.sol";
import {SubmitRateLimitExtension} from "../../contracts/mainnet-checkpoint/extensions/SubmitRateLimitExtension.sol";
import {TokenTransferFilterExtension} from "../../contracts/mainnet-checkpoint/extensions/TokenTransferFilterExtension.sol";
import {CwTransportLinkExtension} from "../../contracts/mainnet-checkpoint/extensions/CwTransportLinkExtension.sol";
import {TimelockSubmitExtension} from "../../contracts/mainnet-checkpoint/extensions/TimelockSubmitExtension.sol";
import {MetricsExtension} from "../../contracts/mainnet-checkpoint/extensions/MetricsExtension.sol";
import {ZkStateRootVerifierExtension} from "../../contracts/mainnet-checkpoint/extensions/ZkStateRootVerifierExtension.sol";
import {PaymasterHintExtension} from "../../contracts/mainnet-checkpoint/extensions/PaymasterHintExtension.sol";
import {L2OracleAdapterExtension} from "../../contracts/mainnet-checkpoint/extensions/L2OracleAdapterExtension.sol";
import {BlockHeaderOracleExtension} from "../../contracts/mainnet-checkpoint/extensions/BlockHeaderOracleExtension.sol";
import {MinPaymentValueExtension} from "../../contracts/mainnet-checkpoint/extensions/MinPaymentValueExtension.sol";
import {LegacyCheckpointAdapter} from "../../contracts/mainnet-checkpoint/LegacyCheckpointAdapter.sol";

/// @notice Deploy all optional extension modules + legacy read adapter (non-proxy).
contract DeployAllCheckpointExtensions is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address admin = vm.envOr("CHECKPOINT_ADMIN", vm.addr(pk));
        address checkpoint = vm.envAddress("CHAIN138_MAINNET_CHECKPOINT_PROXY");
        address mirror = vm.envOr("TRANSACTION_MIRROR_MAINNET", address(0));
        address tether = vm.envOr("MAINNET_TETHER_ADDRESS", address(0));

        vm.startBroadcast(pk);
        console.log("MirrorDetail:", address(new MirrorDetailExtension()));
        console.log("ValidatorSig:", address(new ValidatorSigVerifierExtension()));
        console.log("AttestationURI:", address(new AttestationURIExtension()));
        console.log("RateLimit:", address(new SubmitRateLimitExtension()));
        console.log("TokenFilter:", address(new TokenTransferFilterExtension()));
        console.log("CwLink:", address(new CwTransportLinkExtension()));
        console.log("Timelock:", address(new TimelockSubmitExtension()));
        console.log("Metrics:", address(new MetricsExtension()));
        console.log("ZkStateRoot:", address(new ZkStateRootVerifierExtension()));
        console.log("PaymasterHint:", address(new PaymasterHintExtension()));
        console.log("L2Oracle:", address(new L2OracleAdapterExtension()));
        console.log("BlockOracle:", address(new BlockHeaderOracleExtension(admin)));
        console.log("MinPayment:", address(new MinPaymentValueExtension()));
        console.log("AddressActivityRegistry: deploy separately via scripts/deployment/deploy-address-activity-registry.sh");
        if (mirror != address(0) && tether != address(0)) {
            console.log("LegacyAdapter:", address(new LegacyCheckpointAdapter(checkpoint, mirror, tether)));
        }
        vm.stopBroadcast();
    }
}
