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

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

/**
 * @notice Deploy PaymentChannelManager to the chain specified by RPC (Mainnet or Chain-138).
 * Set CHANNEL_ADMIN (or uses deployer), CHALLENGE_WINDOW_SECONDS (default 86400 = 24h).
 */
contract DeployPaymentChannelManager is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(pk);
        address admin = vm.envOr("CHANNEL_ADMIN", deployer);
        uint256 challengeWindow = vm.envOr("CHALLENGE_WINDOW_SECONDS", uint256(86400)); // 24h default

        vm.startBroadcast(pk);
        PaymentChannelManager manager = new PaymentChannelManager(admin, challengeWindow);
        console.log("PaymentChannelManager deployed at:", address(manager));
        console.log("Admin:", admin);
        console.log("Challenge window (seconds):", challengeWindow);
        vm.stopBroadcast();
    }
}
