%% This Source Code Form is subject to the terms of the Mozilla Public
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2026 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

{mapping, "federation.exchanges.connection_close_timeout", "rabbitmq_exchange_federation.connection_close_timeout", [
    {datatype, {integer, non_negative}},
    {validators, ["connection_close_timeout"]}
]}.

{validator, "connection_close_timeout", "timeout must not exceed 5000ms",
fun(Timeout) when is_integer(Timeout) ->
    Timeout =< 5000
end}.

%% Shutdown pacing configuration

{mapping, "federation.exchanges.shutdown.link_batch_size", "rabbitmq_exchange_federation.shutdown_link_batch_size", [
    {datatype, {integer, positive}}
]}.

{translation, "rabbitmq_exchange_federation.shutdown_link_batch_size",
fun(Conf) ->
    case cuttlefish:conf_get("federation.exchanges.shutdown.link_batch_size", Conf, undefined) of
        undefined -> cuttlefish:unset();
        Value     -> Value
    end
end}.

{mapping, "federation.exchanges.shutdown.timeout", "rabbitmq_exchange_federation.shutdown_timeout", [
    {datatype, {integer, positive}}
]}.

{translation, "rabbitmq_exchange_federation.shutdown_timeout",
fun(Conf) ->
    case cuttlefish:conf_get("federation.exchanges.shutdown.timeout", Conf, undefined) of
        undefined -> cuttlefish:unset();
        Value     -> Value
    end
end}.

{mapping, "federation.exchanges.shutdown.throttle_delay", "rabbitmq_exchange_federation.shutdown_throttle_delay", [
    {datatype, {integer, non_negative}}
]}.

{translation, "rabbitmq_exchange_federation.shutdown_throttle_delay",
fun(Conf) ->
    case cuttlefish:conf_get("federation.exchanges.shutdown.throttle_delay", Conf, undefined) of
        undefined -> cuttlefish:unset();
        Value     -> Value
    end
end}.
