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

# gazelle:exclude test/src

APP_NAME = "rabbitmq_web_stomp"

APP_DESCRIPTION = "RabbitMQ STOMP-over-WebSockets support"

APP_MODULE = "rabbit_web_stomp_app"

APP_ENV = """[
	    {tcp_config, [{port, 15674}]},
	    {ssl_config, []},
	    {num_tcp_acceptors, 10},
	    {num_ssl_acceptors, 10},
	    {cowboy_opts, []},
	    {proxy_protocol, false},
	    {ws_frame, text},
	    {use_http_auth, false}
	  ]"""

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 amqp_client
# gazelle:erlang_app_dep_exclude cowlib
# gazelle:erlang_app_dep_exclude ranch

rabbitmq_app(
    name = "erlang_app",
    srcs = [":all_srcs"],
    hdrs = [":public_hdrs"],
    app_description = APP_DESCRIPTION,
    app_env = APP_ENV,
    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",
        "//deps/rabbit_common:erlang_app",
        "//deps/rabbitmq_stomp:erlang_app",
        "@cowboy//:erlang_app",
    ],
)

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

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

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

eunit(
    name = "eunit",
    compiled_suites = [
        ":test_src_rabbit_ws_test_util_beam",
        ":test_src_rfc6455_client_beam",
        ":test_src_stomp_beam",
    ],
    target = ":test_erlang_app",
)

broker_for_integration_suites()

rabbitmq_integration_suite(
    name = "amqp_stomp_SUITE",
    additional_beam = [
        "test/src/rabbit_ws_test_util.beam",
        "test/src/rfc6455_client.beam",
        "test/src/stomp.beam",
    ],
)

rabbitmq_integration_suite(
    name = "config_schema_SUITE",
)

rabbitmq_integration_suite(
    name = "cowboy_websocket_SUITE",
    additional_beam = [
        "test/src/rabbit_ws_test_util.beam",
        "test/src/rfc6455_client.beam",
        "test/src/stomp.beam",
    ],
)

rabbitmq_integration_suite(
    name = "proxy_protocol_SUITE",
    additional_beam = [
        "test/src/rabbit_ws_test_util.beam",
        "test/src/rfc6455_client.beam",
        "test/src/stomp.beam",
    ],
)

rabbitmq_integration_suite(
    name = "raw_websocket_SUITE",
    additional_beam = [
        "test/src/rabbit_ws_test_util.beam",
        "test/src/rfc6455_client.beam",
        "test/src/stomp.beam",
    ],
)

rabbitmq_suite(
    name = "unit_SUITE",
    size = "small",
)

assert_suites()

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