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",
    "rabbitmq_app",
)
load(
    ":app.bzl",
    "all_beam_files",
    "all_srcs",
    "all_test_beam_files",
    "test_suite_beam_files",
)

# gazelle:erlang_always_generate_test_beam_files

APP_NAME = "rabbitmq_top"

APP_DESCRIPTION = "RabbitMQ Top"

APP_MODULE = "rabbit_top_app"

all_beam_files(name = "all_beam_files")

all_test_beam_files(name = "all_test_beam_files")

all_srcs(name = "all_srcs")

test_suite_beam_files(name = "test_suite_beam_files")

# gazelle:erlang_app_dep_exclude rabbit
# gazelle:erlang_app_dep_exclude rabbitmq_management_agent

rabbitmq_app(
    name = "erlang_app",
    srcs = [":all_srcs"],
    hdrs = [":public_hdrs"],
    app_description = APP_DESCRIPTION,
    app_extra_keys = BROKER_VERSION_REQUIREMENTS_ANY,
    app_module = APP_MODULE,
    app_name = APP_NAME,
    beam_files = [":beam_files"],
    license_files = [":license_files"],
    priv = [":priv"],
    deps = [
        "//deps/rabbit:erlang_app",  # keep
        "//deps/rabbit_common:erlang_app",
        "//deps/rabbitmq_management:erlang_app",
    ],
)

xref(
    name = "xref",
    target = ":erlang_app",
)

plt(
    name = "deps_plt",
    for_target = ":erlang_app",
    ignore_warnings = True,
    libs = ["@rules_elixir//elixir"],  # keep
    plt = "//:base_plt",
)

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

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

assert_suites()
