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

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

/**
 * @title RegisterGRUCompliantTokens
 * @notice Register all c* (GRU compliant) tokens in UniversalAssetRegistry as AssetType.GRU for bridge and pool integration.
 * @dev Run after deploying c* tokens. Uses registerGRUCompliantAsset (no timelock). Env: UNIVERSAL_ASSET_REGISTRY; optional per-token: CUSDT_ADDRESS_138, CUSDC_ADDRESS_138, CEURC_ADDRESS_138, etc.
 */
contract RegisterGRUCompliantTokens 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_ADDRESS_138",  address(0)), "Tether USD (Compliant)",           "cUSDT");
        _register(registry, vm.envOr("CUSDC_ADDRESS_138",  address(0)), "USD Coin (Compliant)",             "cUSDC");
        _register(registry, vm.envOr("CAUSDT_ADDRESS_138", address(0)), "Alltra USD Token (Compliant)",     "cAUSDT");
        _register(registry, vm.envOr("CEURC_ADDRESS_138",  address(0)), "Euro Coin (Compliant)",            "cEURC");
        _register(registry, vm.envOr("CEURT_ADDRESS_138",  address(0)), "Tether EUR (Compliant)",          "cEURT");
        _register(registry, vm.envOr("CGBPC_ADDRESS_138",  address(0)), "Pound Sterling (Compliant)",       "cGBPC");
        _register(registry, vm.envOr("CGBPT_ADDRESS_138",  address(0)), "Tether GBP (Compliant)",          "cGBPT");
        _register(registry, vm.envOr("CAUDC_ADDRESS_138",  address(0)), "Australian Dollar (Compliant)",   "cAUDC");
        _register(registry, vm.envOr("CJPYC_ADDRESS_138",  address(0)), "Japanese Yen (Compliant)",        "cJPYC");
        _register(registry, vm.envOr("CCHFC_ADDRESS_138",  address(0)), "Swiss Franc (Compliant)",         "cCHFC");
        _register(registry, vm.envOr("CCADC_ADDRESS_138",  address(0)), "Canadian Dollar (Compliant)",     "cCADC");
        _register(registry, vm.envOr("CXAUC_ADDRESS_138",  address(0)), "Gold (Compliant)",                "cXAUC");
        _register(registry, vm.envOr("CXAUT_ADDRESS_138",  address(0)), "Tether XAU (Compliant)",          "cXAUT");

        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:", symbol, vm.toString(tokenAddr));
    }
}
