load("@rules_erlang//:eunit2.bzl", "eunit")
load("@rules_erlang//:xref2.bzl", "xref")
load("@rules_erlang//:dialyze.bzl", "dialyze", "plt")
load(
    "//:rabbitmq.bzl",
    "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",
)

APP_NAME = "oauth2_client"

APP_DESCRIPTION = "OAuth 2.0 client from the RabbitMQ Project"

APP_MODULE = "oauth2_client_app"

# gazelle:erlang_app_extra_app ssl
# gazelle:erlang_app_extra_app inets
# gazelle:erlang_app_extra_app crypto
# gazelle:erlang_app_extra_app public_key

# gazelle:erlang_app_dep_exclude rabbit

rabbitmq_app(
    name = "erlang_app",
    srcs = [":all_srcs"],
    hdrs = [":public_hdrs"],
    app_description = APP_DESCRIPTION,
    app_module = APP_MODULE,
    app_name = APP_NAME,
    beam_files = [":beam_files"],
    extra_apps = [
        "crypto",
        "inets",
        "ssl",
        "public_key",
    ],
    license_files = [":license_files"],
    priv = [":priv"],
    deps = [
        "//deps/rabbit_common:erlang_app",
        "@jose//:erlang_app",
    ],
)

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

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

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

eunit(
    name = "eunit",
    compiled_suites = [
        ":test_oauth_http_mock_beam",
        ":test_oauth2_client_test_util_beam",
    ],
    target = ":test_erlang_app",
)

all_srcs(name = "all_srcs")

all_beam_files(name = "all_beam_files")

all_test_beam_files(name = "all_test_beam_files")

test_suite_beam_files(name = "test_suite_beam_files")

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

broker_for_integration_suites()

rabbitmq_integration_suite(
    name = "system_SUITE",
    size = "small",
    additional_beam = [
        "test/oauth_http_mock.beam",
        "test/oauth2_client_test_util.beam",
    ],
    runtime_deps = [
        "@cowboy//:erlang_app",
    ],
)

rabbitmq_suite(
    name = "unit_SUITE",
    size = "small",
    additional_beam = [
        "test/oauth2_client_test_util.beam",
    ],
)

assert_suites()
