// 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 {Chain138MainnetCheckpoint} from "../../contracts/mainnet-checkpoint/Chain138MainnetCheckpoint.sol";

contract DeployChain138MainnetCheckpoint 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_MAINNET");
        uint64 sourceSelector = uint64(vm.envUint("CCIP_CHAIN_SELECTOR_138"));
        address batchEmitter = vm.envOr("CHAIN138_BATCH_EMITTER", address(0));

        vm.startBroadcast(pk);
        Chain138MainnetCheckpoint impl = new Chain138MainnetCheckpoint();
        bytes memory initData = abi.encodeCall(
            Chain138MainnetCheckpoint.initialize,
            (admin, ccipRouter, sourceSelector, batchEmitter)
        );
        ERC1967Proxy proxy = new ERC1967Proxy(address(impl), initData);
        console.log("Chain138MainnetCheckpoint impl:", address(impl));
        console.log("Chain138MainnetCheckpoint proxy:", address(proxy));
        console.log("Admin:", admin);
        vm.stopBroadcast();
    }
}
