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

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

/// @notice Wire reserve store notary gate + align attestation threshold with jurisdiction policy.
contract WireOMNLWeb3Compliance is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address reserves = vm.envAddress("OMNL_RESERVE_COMMITMENT_STORE");
        address notary = vm.envAddress("OMNL_NOTARY_REGISTRY");
        OMNLComplianceMultisig multisig = OMNLComplianceMultisig(payable(vm.envAddress("OMNL_COMPLIANCE_MULTISIG")));

        bytes32 jurId = keccak256(bytes(vm.envOr("OMNL_JURISDICTION_ID", string("ID"))));
        bytes32 matrixId = keccak256(bytes(vm.envOr("OMNL_MATRIX_CONTROL_ID", string("ID-OMNL-001"))));
        bool requireNotary = vm.envOr("OMNL_REQUIRE_NOTARIZED_RESERVE", true);
        uint256 attTh = vm.envOr("OMNL_RESERVE_ATTESTATION_THRESHOLD", uint256(3));

        vm.startBroadcast(pk);
        ReserveCommitmentStore(reserves).configureNotaryGate(notary, requireNotary, jurId, matrixId);
        ReserveCommitmentStore(reserves).setAttestationThreshold(attTh);

        address admin = vm.addr(pk);
        OMNLNotaryRegistry(notary).grantRole(OMNLNotaryRegistry(notary).NOTARY_ADMIN_ROLE(), address(multisig));
        multisig.grantRole(multisig.PROPOSER_ROLE(), admin);
        vm.stopBroadcast();

        console2.log("Wired notary gate on ReserveCommitmentStore", reserves);
    }
}
