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

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

/**
 * @title DeployCCIPLoggerChain138 - Deploy CCIPLogger to ChainID 138
 * @notice This script deploys CCIPLogger to ChainID 138
 * @dev CCIPLogger logs CCIP messages for monitoring and debugging
 */
contract DeployCCIPLoggerChain138 is Script {
    uint256 constant CHAIN138 = 138;

    function run() external {
        uint256 chainId = block.chainid;
        require(chainId == CHAIN138, "This script is only for ChainID 138");

        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(deployerPrivateKey);

        // Load CCIP Router address
        address ccipRouter = vm.envAddress("CCIP_ROUTER_ADDRESS");
        require(ccipRouter != address(0), "CCIP_ROUTER_ADDRESS not set");

        console.log("==========================================");
        console.log("CCIPLogger Deployment - ChainID 138");
        console.log("==========================================");
        console.log("Chain ID:", chainId);
        console.log("Deployer:", deployer);
        console.log("Deployer Balance:", deployer.balance / 1e18, "ETH");
        console.log("CCIP Router:", ccipRouter);
        console.log("");

        vm.startBroadcast(deployerPrivateKey);

        // Note: CCIPLogger contract needs to be available
        // If CCIPLogger.sol doesn't exist, this will fail at compilation
        // For now, we'll create a simple logger contract inline
        
        // Deploy a simple CCIP Logger contract
        CCIPLogger logger = new CCIPLogger(ccipRouter);
        
        console.log("CCIPLogger deployed at:", address(logger));
        console.log("CCIP Router:", ccipRouter);

        vm.stopBroadcast();

        console.log("\n=== Deployment Summary ===");
        console.log("CCIPLogger:", address(logger));
        console.log("CCIP Router:", ccipRouter);
    }
}

// Simple CCIP Logger contract
contract CCIPLogger {
    address public immutable router;
    
    event MessageLogged(
        bytes32 indexed messageId,
        uint64 indexed sourceChainSelector,
        address sender,
        bytes data,
        uint256 timestamp
    );
    
    constructor(address _router) {
        require(_router != address(0), "CCIPLogger: zero router");
        router = _router;
    }
    
    function logMessage(
        bytes32 messageId,
        uint64 sourceChainSelector,
        address sender,
        bytes calldata data
    ) external {
        emit MessageLogged(messageId, sourceChainSelector, sender, data, block.timestamp);
    }
}

