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

import {Script, console2} from "forge-std/Script.sol";
import {InstrumentRegistry} from "../../contracts/hybx-omnl/InstrumentRegistry.sol";
import {ReserveCommitmentStore} from "../../contracts/hybx-omnl/ReserveCommitmentStore.sol";
import {OMNLCircuitBreaker} from "../../contracts/hybx-omnl/OMNLCircuitBreaker.sol";
import {ComplianceCore} from "../../contracts/hybx-omnl/ComplianceCore.sol";
import {OMNLJurisdictionPolicyRegistry} from "../../contracts/hybx-omnl/OMNLJurisdictionPolicyRegistry.sol";
import {OMNLNotaryRegistry} from "../../contracts/hybx-omnl/OMNLNotaryRegistry.sol";
import {OMNLComplianceMultisig} from "../../contracts/hybx-omnl/OMNLComplianceMultisig.sol";

/// @notice Deploy core OMNL stack + Web3 compliance (registry, reserves, breakers, compliance, notary, multisig).
contract DeployOMNLStack is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address admin = vm.addr(pk);

        vm.startBroadcast(pk);

        InstrumentRegistry registry = new InstrumentRegistry(admin);
        ReserveCommitmentStore reserves = new ReserveCommitmentStore(admin);
        OMNLCircuitBreaker breakers = new OMNLCircuitBreaker(admin);
        ComplianceCore core = new ComplianceCore(address(registry), address(reserves), address(breakers));

        OMNLJurisdictionPolicyRegistry jurisdiction = new OMNLJurisdictionPolicyRegistry(admin);
        OMNLNotaryRegistry notary = new OMNLNotaryRegistry(admin, address(jurisdiction));
        OMNLComplianceMultisig multisig = new OMNLComplianceMultisig(admin, address(notary));

        bytes32 jurId = keccak256("ID");
        bytes32 matrixId = keccak256("ID-OMNL-001");
        reserves.configureNotaryGate(address(notary), false, jurId, matrixId);

        vm.stopBroadcast();

        console2.log("InstrumentRegistry", address(registry));
        console2.log("ReserveCommitmentStore", address(reserves));
        console2.log("OMNLCircuitBreaker", address(breakers));
        console2.log("ComplianceCore", address(core));
        console2.log("OMNLJurisdictionPolicyRegistry", address(jurisdiction));
        console2.log("OMNLNotaryRegistry", address(notary));
        console2.log("OMNLComplianceMultisig", address(multisig));
    }
}
