load("@rules_erlang//:eunit2.bzl", "eunit")
load("@rules_erlang//:xref2.bzl", "xref")
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
load(
    "//:rabbitmq.bzl",
    "BROKER_VERSION_REQUIREMENTS_ANY",
    "RABBITMQ_DIALYZER_OPTS",
    "assert_suites",
    "broker_for_integration_suites",
    "rabbitmq_app",
    "rabbitmq_integration_suite",
)
load(
    ":app.bzl",
    "all_beam_files",
    "all_srcs",
    "all_test_beam_files",
    "test_suite_beam_files",
)

APP_NAME = "rabbitmq_consistent_hash_exchange"

APP_DESCRIPTION = "Consistent Hash Exchange Type"

all_beam_files(name = "all_beam_files")

all_srcs(name = "all_srcs")

test_suite_beam_files(name = "test_suite_beam_files")

rabbitmq_app(
    name = "erlang_app",
    srcs = [":all_srcs"],
    hdrs = [":public_hdrs"],
    app_description = APP_DESCRIPTION,
    app_extra_keys = BROKER_VERSION_REQUIREMENTS_ANY,
    app_name = APP_NAME,
    beam_files = [":beam_files"],
    license_files = [":license_files"],
    priv = [":priv"],
    deps = [
        "//deps/rabbit:erlang_app",
        "//deps/rabbit_common:erlang_app",
        "@khepri//:erlang_app",
        "@khepri_mnesia_migration//:erlang_app",
    ],
)

xref(
    name = "xref",
    additional_libs = [
        "//deps/rabbitmq_cli:erlang_app",  # keep
    ],
    target = ":erlang_app",
)

plt(
    name = "deps_plt",
    apps = [
        "mnesia",  # keep
    ],
    for_target = ":erlang_app",
    ignore_warnings = True,
    libs = ["//deps/rabbitmq_cli:elixir"],  # keep
    plt = "//:base_plt",
    deps = ["//deps/rabbitmq_cli:erlang_app"],  # keep
)

dialyze(
    name = "dialyze",
    dialyzer_opts = RABBITMQ_DIALYZER_OPTS,
    plt = ":deps_plt",
    target = ":erlang_app",
)

eunit(
    name = "eunit",
    target = ":test_erlang_app",
)

broker_for_integration_suites()

rabbitmq_integration_suite(
    name = "rabbit_exchange_type_consistent_hash_SUITE",
    shard_count = 7,
    runtime_deps = [
        "//deps/rabbitmq_amqp_client:erlang_app",
    ],
)

assert_suites()

alias(
    name = "rabbitmq_consistent_hash_exchange",
    actual = ":erlang_app",
    visibility = ["//visibility:public"],
)

all_test_beam_files(name = "all_test_beam_files")
