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

import {Script, console} from "forge-std/Script.sol";
import {PriceFeedKeeper} from "../../contracts/reserve/PriceFeedKeeper.sol";

/**
 * @title CheckUpkeep
 * @notice Script to check if upkeep is needed
 * @dev Read-only script to check keeper status
 */
contract CheckUpkeep is Script {
    function run() external view {
        address keeperAddress = vm.envAddress("PRICE_FEED_KEEPER_ADDRESS");
        PriceFeedKeeper keeper = PriceFeedKeeper(keeperAddress);

        console.log("=== Check Keeper Upkeep ===");
        console.log("Keeper Address:", keeperAddress);
        console.log("");

        // Check if upkeep is needed
        (bool updateNeeded, address[] memory assets) = keeper.checkUpkeep();

        console.log("Needs Update:", updateNeeded);
        console.log("Assets needing update:", assets.length);

        if (assets.length > 0) {
            console.log("");
            console.log("Assets:");
            for (uint256 i = 0; i < assets.length; i++) {
                bool assetNeedsUpdate = keeper.needsUpdate(assets[i]);
                console.log("Asset %s: %s - Needs Update: %s", i + 1, assets[i], assetNeedsUpdate);
            }
        }

        // Get tracked assets
        address[] memory trackedAssets = keeper.getTrackedAssets();
        console.log("");
        console.log("Total Tracked Assets:", trackedAssets.length);

        // Get update interval
        uint256 updateInterval = keeper.updateInterval();
        console.log("Update Interval:", updateInterval, "seconds");
    }
}

