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

import "forge-std/Script.sol";
import "forge-std/console.sol";
import "../../contracts/smart-accounts/AccountWalletRegistryExtended.sol";

/**
 * @title DeployAccountWalletRegistryExtended
 * @notice Deploys the extended AccountWalletRegistry with Smart Account support
 * @dev This script deploys AccountWalletRegistryExtended to ChainID 138
 */
contract DeployAccountWalletRegistryExtended is Script {
    function run() external {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(deployerPrivateKey);
        string memory rpcUrl = vm.envString("RPC_URL_138");
        
        // Get addresses from environment or config
        address smartAccountFactory = vm.envAddress("SMART_ACCOUNT_FACTORY");
        address entryPoint = vm.envAddress("ENTRY_POINT");
        
        console.log("Deployer:", deployer);
        console.log("RPC URL:", rpcUrl);
        console.log("Chain ID: 138");
        console.log("Smart Account Factory:", smartAccountFactory);
        console.log("EntryPoint:", entryPoint);
        
        vm.startBroadcast(deployerPrivateKey);
        
        // Deploy AccountWalletRegistryExtended
        AccountWalletRegistryExtended extendedRegistry = new AccountWalletRegistryExtended(
            deployer, // admin
            smartAccountFactory,
            entryPoint
        );
        
        vm.stopBroadcast();
        
        console.log("\n=== Deployment Summary ===");
        console.log("AccountWalletRegistryExtended:", address(extendedRegistry));
        console.log("\nNext steps:");
        console.log("1. Grant ACCOUNT_MANAGER_ROLE to authorized addresses");
        console.log("2. Update AccountWalletRegistry references in SettlementOrchestrator");
        console.log("3. Test linking smart accounts");
        console.log("4. Test linking EOA wallets");
    }
}
