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

import "forge-std/Script.sol";
import {IndexFacet} from "@gru/facets/IndexFacet.sol";
import {IERC173} from "@gru/interfaces/IERC173.sol";

/// @notice Seed unit weights (1e18) for each Li* index on the M00 diamond hub.
contract SeedM00LiIndexWeights138 is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address diamond = vm.envAddress("M00_DIAMOND_HUB");
        uint256 chainId = 138;

        string[5] memory tickers = ["LiXAU", "LiPMG", "LiBMG1", "LiBMG2", "LiBMG3"];

        vm.startBroadcast(pk);
        for (uint256 i = 0; i < tickers.length; i++) {
            bytes32 indexId = keccak256(abi.encode(tickers[i], chainId));
            bytes32[] memory keys = new bytes32[](1);
            keys[0] = keccak256(abi.encode(tickers[i]));
            uint256[] memory weights = new uint256[](1);
            weights[0] = 1e18;
            IndexFacet(diamond).setWeights(indexId, keys, weights, 1, keccak256("M00_LI_v1"));
        }
        address newOwner = vm.envOr("M00_DIAMOND_OWNER", vm.envOr("GOVERNANCE_CONTROLLER", address(0)));
        if (newOwner != address(0)) {
            IERC173(diamond).transferOwnership(newOwner);
        }
        vm.stopBroadcast();
    }
}
