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

import "forge-std/Script.sol";
import "../../contracts/reserve/ChainlinkKeeperCompatible.sol";
import "../../contracts/reserve/PriceFeedKeeper.sol";

/**
 * @title DeployChainlinkKeeper
 * @notice Deploy ChainlinkKeeperCompatible wrapper for PriceFeedKeeper
 */
contract DeployChainlinkKeeper is Script {
    function run() external {
        uint256 chainId = block.chainid;
        require(chainId == 138, "This script is for ChainID 138 only");

        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(deployerPrivateKey);

        address deployer = vm.addr(deployerPrivateKey);
        console.log("=== Deploy Chainlink Keeper Compatible (ChainID 138) ===");
        console.log("Deployer:", deployer);
        console.log("");

        address keeperAddress = vm.envAddress("PRICE_FEED_KEEPER_ADDRESS");
        console.log("PriceFeedKeeper:", keeperAddress);

        console.log("Deploying ChainlinkKeeperCompatible...");
        ChainlinkKeeperCompatible chainlinkKeeper = new ChainlinkKeeperCompatible(keeperAddress);
        console.log("ChainlinkKeeperCompatible deployed at:", address(chainlinkKeeper));

        console.log("");
        console.log("=== Deployment Summary ===");
        console.log("ChainlinkKeeperCompatible:", address(chainlinkKeeper));
        console.log("PriceFeedKeeper:", keeperAddress);
        console.log("");
        console.log("=== Next Steps ===");
        console.log("1. Register upkeep with Chainlink KeeperRegistry:");
        console.log("   node scripts/reserve/chainlink-keeper-setup.js");
        console.log("2. Or use Chainlink UI: https://automation.chain.link");
        console.log("");
        console.log("=== Export to .env ===");
        console.log("export CHAINLINK_KEEPER_COMPATIBLE_ADDRESS=", vm.toString(address(chainlinkKeeper)));

        vm.stopBroadcast();
    }
}

