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

import {Script, console} from "forge-std/Script.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Chain138BatchEmitter} from "../../contracts/mainnet-checkpoint/chain138/Chain138BatchEmitter.sol";

contract DeployChain138BatchEmitter is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address admin = vm.envOr("CHECKPOINT_ADMIN", vm.addr(pk));
        address ccipRouter = vm.envAddress("CCIP_ROUTER_CHAIN138");
        address linkToken = vm.envAddress("LINK_TOKEN_CHAIN138");
        uint64 mainnetSelector = uint64(vm.envUint("CCIP_CHAIN_SELECTOR_MAINNET"));
        address mainnetCheckpoint = vm.envAddress("CHAIN138_MAINNET_CHECKPOINT_PROXY");

        vm.startBroadcast(pk);
        Chain138BatchEmitter impl = new Chain138BatchEmitter();
        bytes memory initData = abi.encodeCall(
            Chain138BatchEmitter.initialize,
            (admin, ccipRouter, linkToken, mainnetSelector, mainnetCheckpoint)
        );
        ERC1967Proxy proxy = new ERC1967Proxy(address(impl), initData);
        console.log("Chain138BatchEmitter impl:", address(impl));
        console.log("Chain138BatchEmitter proxy:", address(proxy));
        vm.stopBroadcast();
    }
}
