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

import "forge-std/Script.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "../../contracts/registry/UniversalAssetRegistry.sol";
import "../../contracts/governance/GovernanceController.sol";

contract DeployCore is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address deployer = vm.addr(pk);
        
        vm.startBroadcast(pk);
        
        // Deploy UniversalAssetRegistry behind proxy (UUPS upgradeable)
        UniversalAssetRegistry registryImpl = new UniversalAssetRegistry();
        bytes memory registryInitData = abi.encodeCall(UniversalAssetRegistry.initialize, (deployer));
        ERC1967Proxy registryProxy = new ERC1967Proxy(address(registryImpl), registryInitData);
        UniversalAssetRegistry registry = UniversalAssetRegistry(address(registryProxy));
        registry.addValidator(deployer);
        
        // Deploy GovernanceController behind proxy (UUPS upgradeable)
        GovernanceController governanceImpl = new GovernanceController();
        bytes memory governanceInitData = abi.encodeCall(GovernanceController.initialize, (address(registry), deployer));
        ERC1967Proxy governanceProxy = new ERC1967Proxy(address(governanceImpl), governanceInitData);
        GovernanceController governance = GovernanceController(address(governanceProxy));
        
        vm.stopBroadcast();
        
        console.log("UNIVERSAL_ASSET_REGISTRY=", address(registry));
        console.log("GOVERNANCE_CONTROLLER=", address(governance));
    }
}
