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

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

/**
 * @title DeployGelatoKeeper
 * @notice Deploy GelatoKeeperCompatible wrapper for PriceFeedKeeper
 */
contract DeployGelatoKeeper 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 Gelato Keeper Compatible (ChainID 138) ===");
        console.log("Deployer:", deployer);
        console.log("");

        address keeperAddress = vm.envAddress("PRICE_FEED_KEEPER_ADDRESS");
        address gelato = vm.envOr("GELATO_OPS", address(0x527a819db1eb0e34426297b03bae11F2f8B3A19E)); // Default Gelato Ops

        console.log("PriceFeedKeeper:", keeperAddress);
        console.log("Gelato Ops:", gelato);

        console.log("Deploying GelatoKeeperCompatible...");
        GelatoKeeperCompatible gelatoKeeper = new GelatoKeeperCompatible(keeperAddress, gelato);
        console.log("GelatoKeeperCompatible deployed at:", address(gelatoKeeper));

        console.log("");
        console.log("=== Deployment Summary ===");
        console.log("GelatoKeeperCompatible:", address(gelatoKeeper));
        console.log("PriceFeedKeeper:", keeperAddress);
        console.log("Gelato Ops:", gelato);
        console.log("");
        console.log("=== Next Steps ===");
        console.log("1. Create task with Gelato:");
        console.log("   node scripts/reserve/gelato-keeper-setup.js");
        console.log("2. Or use Gelato UI: https://app.gelato.network");
        console.log("");
        console.log("=== Export to .env ===");
        console.log("export GELATO_KEEPER_COMPATIBLE_ADDRESS=", vm.toString(address(gelatoKeeper)));

        vm.stopBroadcast();
    }
}

