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

import "forge-std/Script.sol";
import "../../../contracts/registry/ChainRegistry.sol";
import "../../../contracts/bridge/adapters/non-evm/SolanaAdapter.sol";

contract DeploySolanaAdapter is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address admin = vm.addr(pk);
        address chainRegistry = vm.envAddress("CHAIN_REGISTRY_ADDRESS");

        ChainRegistry registry = ChainRegistry(chainRegistry);

        vm.startBroadcast(pk);

        SolanaAdapter solanaAdapter = new SolanaAdapter(admin);
        ChainRegistry.ChainMetadata memory existing = registry.getNonEVMChain("Solana-Mainnet");

        if (existing.adapter == address(0)) {
            registry.registerNonEVMChain(
                "Solana-Mainnet",
                ChainRegistry.ChainType.Solana,
                address(solanaAdapter),
                "https://solscan.io",
                32,
                1,
                true,
                ""
            );
        } else {
            registry.updateAdapter(0, "Solana-Mainnet", address(solanaAdapter));
            registry.setChainActive(0, "Solana-Mainnet", true);
        }

        vm.stopBroadcast();

        console.log("SolanaAdapter:", address(solanaAdapter));
        console.log("ChainRegistry:", chainRegistry);
    }
}
