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

import {Script, console} from "forge-std/Script.sol";
import {Aggregator} from "../contracts/oracle/Aggregator.sol";
import {Proxy} from "../contracts/oracle/Proxy.sol";

contract DeployOracle is Script {
    function run() external {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(deployerPrivateKey);
        
        string memory description = vm.envOr("ORACLE_DESCRIPTION", string("ETH/USD Price Feed"));
        uint256 heartbeat = vm.envOr("ORACLE_HEARTBEAT", uint256(60));
        uint256 deviationThreshold = vm.envOr("ORACLE_DEVIATION_THRESHOLD", uint256(50));
        
        console.log("Deploying Oracle with address:", deployer);
        console.log("Description:", description);
        console.log("Heartbeat:", heartbeat);
        console.log("Deviation Threshold:", deviationThreshold);
        
        vm.startBroadcast(deployerPrivateKey);
        
        // Deploy Aggregator implementation
        Aggregator aggregator = new Aggregator(
            description,
            deployer,
            heartbeat,
            deviationThreshold
        );
        console.log("Aggregator deployed at:", address(aggregator));
        
        // Deploy Proxy
        Proxy proxy = new Proxy(address(aggregator), deployer);
        console.log("Proxy deployed at:", address(proxy));
        
        vm.stopBroadcast();
    }
}

