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

import "forge-std/Script.sol";
import "../../../contracts/registry/ChainRegistry.sol";
import "../../../contracts/bridge/adapters/evm/EVMAdapter.sol";
import "../../../contracts/bridge/adapters/evm/XDCAdapter.sol";
import "../../../contracts/bridge/adapters/evm/AlltraAdapter.sol";
import "../../../contracts/bridge/adapters/non-evm/XRPLAdapter.sol";
import "../../../contracts/bridge/adapters/non-evm/StellarAdapter.sol";
import "../../../contracts/bridge/adapters/non-evm/SolanaAdapter.sol";
import "../../../contracts/bridge/adapters/non-evm/TezosAdapter.sol";
import "../../../contracts/bridge/adapters/non-evm/TronAdapter.sol";
import "../../../contracts/bridge/adapters/hyperledger/FireflyAdapter.sol";
import "../../../contracts/bridge/adapters/hyperledger/CactiAdapter.sol";
import "../../../contracts/bridge/adapters/hyperledger/FabricAdapter.sol";

contract DeployAllAdapters is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(pk);
        address bridge = vm.envAddress("UNIVERSAL_BRIDGE_ADDRESS");
        address chainRegistry = vm.envAddress("CHAIN_REGISTRY_ADDRESS");
        
        ChainRegistry registry = ChainRegistry(chainRegistry);
        
        vm.startBroadcast(pk);
        
        // Deploy EVM adapters
        EVMAdapter polygonAdapter = new EVMAdapter(deployer, bridge, 137, "Polygon");
        EVMAdapter arbitrumAdapter = new EVMAdapter(deployer, bridge, 42161, "Arbitrum");
        EVMAdapter optimismAdapter = new EVMAdapter(deployer, bridge, 10, "Optimism");
        EVMAdapter baseAdapter = new EVMAdapter(deployer, bridge, 8453, "Base");
        EVMAdapter avalancheAdapter = new EVMAdapter(deployer, bridge, 43114, "Avalanche");
        EVMAdapter bscAdapter = new EVMAdapter(deployer, bridge, 56, "BSC");
        EVMAdapter ethereumAdapter = new EVMAdapter(deployer, bridge, 1, "Ethereum Mainnet");
        EVMAdapter etherlinkAdapter = new EVMAdapter(deployer, bridge, 42793, "Etherlink Mainnet");
        XDCAdapter xdcAdapter = new XDCAdapter(deployer, bridge);
        AlltraAdapter alltraAdapter = new AlltraAdapter(deployer, bridge);
        
        // Deploy non-EVM adapters
        XRPLAdapter xrplAdapter = new XRPLAdapter(deployer);
        StellarAdapter stellarAdapter = new StellarAdapter(deployer);
        SolanaAdapter solanaAdapter = new SolanaAdapter(deployer);
        TezosAdapter tezosAdapter = new TezosAdapter(deployer);
        TronAdapter tronAdapter = new TronAdapter(deployer);
        
        // Deploy Hyperledger adapters
        FireflyAdapter fireflyAdapter = new FireflyAdapter(deployer, "alltra-bridge");
        CactiAdapter cactiAdapter = new CactiAdapter(deployer, "http://192.168.11.177:4000/api/v1");
        FabricAdapter fabricAdapter = new FabricAdapter(deployer, "bridge-channel", "bridge");
        
        // Register chains
        registry.registerEVMChain(137, address(polygonAdapter), "https://polygonscan.com", 12, 2, "");
        registry.registerEVMChain(42161, address(arbitrumAdapter), "https://arbiscan.io", 12, 1, "");
        registry.registerEVMChain(10, address(optimismAdapter), "https://optimistic.etherscan.io", 12, 2, "");
        registry.registerEVMChain(8453, address(baseAdapter), "https://basescan.org", 12, 2, "");
        registry.registerEVMChain(43114, address(avalancheAdapter), "https://snowtrace.io", 12, 1, "");
        registry.registerEVMChain(56, address(bscAdapter), "https://bscscan.com", 12, 3, "");
        registry.registerEVMChain(1, address(ethereumAdapter), "https://etherscan.io", 12, 12, "");
        registry.registerEVMChain(42793, address(etherlinkAdapter), "https://explorer.etherlink.com", 12, 2, "");
        registry.registerEVMChain(50, address(xdcAdapter), "https://explorer.xdc.network", 12, 2, "");
        
        registry.registerNonEVMChain("XRPL-Mainnet", ChainRegistry.ChainType.XRPL, address(xrplAdapter), "https://xrpscan.com", 1, 4, true, "");
        registry.registerNonEVMChain("Stellar-Mainnet", ChainRegistry.ChainType.Stellar, address(stellarAdapter), "https://stellarchain.io", 1, 5, true, "");
        registry.registerNonEVMChain("Solana-Mainnet", ChainRegistry.ChainType.Solana, address(solanaAdapter), "https://solscan.io", 32, 1, true, "");
        registry.registerNonEVMChain("Tezos-Mainnet", ChainRegistry.ChainType.Other, address(tezosAdapter), "https://tzkt.io", 1, 30, true, "");
        registry.registerNonEVMChain("Tron-Mainnet", ChainRegistry.ChainType.Tron, address(tronAdapter), "https://tronscan.org", 20, 3, true, "");
        registry.registerNonEVMChain("Firefly-Orchestration", ChainRegistry.ChainType.Firefly, address(fireflyAdapter), "", 1, 1, true, "");
        registry.registerNonEVMChain("Cacti-Interoperability", ChainRegistry.ChainType.Cacti, address(cactiAdapter), "", 1, 1, true, "");
        registry.registerNonEVMChain("Fabric-bridge-channel", ChainRegistry.ChainType.Fabric, address(fabricAdapter), "", 1, 1, true, "");
        
        vm.stopBroadcast();
        
        console.log("All adapters deployed and registered!");
    }
}
