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

import "forge-std/Script.sol";
import {UniversalAssetRegistry} from "../../contracts/registry/UniversalAssetRegistry.sol";

/**
 * @title RegisterGRUCompliantTokensV2
 * @notice Stage deployed c* V2 contracts in UniversalAssetRegistry using version-aware symbols.
 * @dev Keeps live V1 symbols untouched while allowing indexers/operators to discover V2 addresses.
 *      Env: UNIVERSAL_ASSET_REGISTRY; optional CUSDT_V2_ADDRESS_138, CUSDC_V2_ADDRESS_138.
 */
contract RegisterGRUCompliantTokensV2 is Script {
    function run() external {
        address registryAddr = vm.envAddress("UNIVERSAL_ASSET_REGISTRY");
        UniversalAssetRegistry registry = UniversalAssetRegistry(registryAddr);
        uint256 pk = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(pk);

        _register(
            registry,
            vm.envOr("CUSDT_V2_ADDRESS_138", address(0)),
            "Tether USD (Compliant V2)",
            "cUSDT.v2"
        );
        _register(
            registry,
            vm.envOr("CUSDC_V2_ADDRESS_138", address(0)),
            "USD Coin (Compliant V2)",
            "cUSDC.v2"
        );

        vm.stopBroadcast();
    }

    function _register(
        UniversalAssetRegistry registry,
        address tokenAddr,
        string memory name,
        string memory symbol
    ) internal {
        if (tokenAddr == address(0)) return;
        if (registry.isAssetActive(tokenAddr)) {
            console.log("Skip (already registered):", symbol, vm.toString(tokenAddr));
            return;
        }
        registry.registerGRUCompliantAsset(tokenAddr, name, symbol, 6, "International");
        console.log("Registered GRU V2:", symbol, vm.toString(tokenAddr));
    }
}
