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

import {Script, console} from "forge-std/Script.sol";
import {CCIPWETH9Bridge} from "../contracts/ccip/CCIPWETH9Bridge.sol";
import {WETH} from "../contracts/tokens/WETH.sol";

contract DeployCCIPWETH9Bridge is Script {
    function run() external {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(deployerPrivateKey);
        
        // Get configuration from environment. Default router: working CCIP router (0x8078A...); do not use 0x80226... (no code).
        address ccipRouter = vm.envOr("CCIP_ROUTER", address(0x8078A09637e47Fa5Ed34F626046Ea2094a5CDE5e));
        // Use canonical Mainnet WETH9 address (predeployed in genesis)
        address weth9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
        // address(0) = pay fees in native ETH; else use LINK/ERC20
        address feeToken = vm.envOr("CCIP_FEE_TOKEN", address(0));
        
        console.log("Deploying CCIPWETH9Bridge with:");
        console.log("  Deployer:", deployer);
        console.log("  CCIP Router:", ccipRouter);
        console.log("  WETH9:", weth9);
        console.log("  Fee Token:", feeToken);
        
        vm.startBroadcast(deployerPrivateKey);
        
        CCIPWETH9Bridge bridge = new CCIPWETH9Bridge(
            ccipRouter,
            weth9,
            feeToken
        );
        
        console.log("CCIPWETH9Bridge deployed at:", address(bridge));
        console.log("  CCIP Router:", address(bridge.ccipRouter()));
        console.log("  WETH9:", bridge.weth9());
        console.log("  Fee Token:", bridge.feeToken());
        console.log("  Admin:", bridge.admin());
        
        vm.stopBroadcast();
    }
}

