{erl_opts, [debug_info, warnings_as_errors]}.

{deps, [
    {telemetry, "~> 1.3"}
]}.

{project_plugins, [
    erlfmt,
    rebar3_hex,
    rebar3_ex_doc,
    rebar3_lint,
    rebar3_hank,
    {rebar3_mutate, "~> 0.4.0"},
    covertool,
    {rebar3_audit, "~> 0.2"},
    {rebar3_sbom,
        {git, "https://github.com/Taure/rebar3_sbom.git", {branch, "feat/include-otp-components"}}}
]}.

{erlfmt, [write]}.

{elvis, [
    {config, [
        #{
            files => ["src/*.erl"],
            ruleset => erl_files_strict,
            rules => [
                %% erlfmt handles line length
                {elvis_text_style, max_line_length, #{limit => 120}},
                {elvis_style, dont_repeat_yourself, #{min_complexity => 15}},
                {elvis_style, atom_naming_convention, #{
                    regex => "^[a-z][a-z_@0-9]*$"
                }},
                {elvis_style, function_naming_convention, #{
                    regex => "^[a-z][a-z_0-9]*$"
                }},
                %% Macros for constants are fine
                {elvis_style, no_macros, disable},
                {elvis_style, no_invalid_dynamic_calls, disable},
                {elvis_style, no_init_lists, disable},
                {elvis_style, state_record_and_type, disable},
                {elvis_style, no_throw, disable},
                %% gen_server:call/2 is standard OTP
                {elvis_style, no_common_caveats_call, disable},
                %% Multi-clause pattern matching functions
                {elvis_style, max_function_length, #{max_length => 120}},
                {elvis_style, max_function_clause_length, #{max_length => 70}},
                {elvis_style, abc_size, #{max_abc_size => 50}},
                {elvis_style, no_deep_nesting, #{level => 5}},
                %% Sigils will be adopted incrementally
                {elvis_style, prefer_sigils, disable},
                %% Strict generators not required yet
                {elvis_style, prefer_strict_generators, disable},
                %% start_link wrapping is OTP convention
                {elvis_style, consistent_ok_error_spec, disable}
            ]
        },
        #{
            files => ["test/*.erl"],
            ruleset => erl_files_strict,
            rules => [
                {elvis_text_style, max_line_length, #{limit => 120}},
                {elvis_style, dont_repeat_yourself, disable},
                {elvis_style, no_macros, disable},
                {elvis_style, no_block_expressions, disable},
                {elvis_style, no_common_caveats_call, disable},
                {elvis_style, no_boolean_in_comparison, disable},
                {elvis_style, no_receive_without_timeout, disable},
                {elvis_style, no_init_lists, disable},
                {elvis_style, max_function_length, disable},
                {elvis_style, max_function_clause_length, disable},
                {elvis_style, max_module_length, disable},
                {elvis_style, no_throw, disable},
                {elvis_style, prefer_sigils, disable}
            ]
        }
    ]}
]}.

{hank, [
    {ignore, [
        {"test/**", [unnecessary_function_arguments]},
        {"src/seki_otel.erl", [unnecessary_function_arguments]},
        {"src/seki_adaptive.erl", [unnecessary_function_arguments]},
        {"src/seki_backend.erl", [unused_callbacks]}
    ]}
]}.

{cover_enabled, true}.
{cover_export_enabled, true}.
{covertool, [{coverdata_files, ["eunit.coverdata"]}]}.

{profiles, [
    {test, [
        {erl_opts, [nowarn_export_all]},
        {deps, [
            {proper, "1.4.0"}
        ]}
    ]}
]}.

{xref_checks, [
    undefined_function_calls,
    undefined_functions,
    locals_not_used,
    deprecated_function_calls,
    deprecated_functions
]}.

{xref_ignores, [
    {otel_ctx, get_current, 0},
    {otel_span, add_event, 3},
    {otel_tracer, current_span_ctx, 0}
]}.

{dialyzer, [
    {warnings, [
        error_handling,
        unmatched_returns
    ]},
    {exclude_mods, [seki_otel]}
]}.

{hex, [{doc, #{provider => ex_doc}}]}.

{ex_doc, [
    {source_url, <<"https://github.com/Taure/seki">>},
    {extras, [
        <<"README.md">>,
        <<"LICENSE.md">>,
        <<"guides/getting-started.md">>,
        <<"guides/rate-limiting.md">>,
        <<"guides/circuit-breaker.md">>,
        <<"guides/nova-integration.md">>,
        <<"guides/phoenix-integration.md">>,
        <<"guides/advanced-patterns.md">>
    ]},
    {main, <<"readme">>},
    {groups_for_extras, [
        {<<"Guides">>, [
            <<"guides/getting-started.md">>,
            <<"guides/rate-limiting.md">>,
            <<"guides/circuit-breaker.md">>,
            <<"guides/nova-integration.md">>,
            <<"guides/phoenix-integration.md">>,
            <<"guides/advanced-patterns.md">>
        ]}
    ]},
    {groups_for_modules, [
        {<<"Core API">>, [
            seki,
            seki_breaker,
            seki_bulkhead,
            seki_retry,
            seki_deadline
        ]},
        {<<"Rate Limiting">>, [
            seki_algorithm,
            seki_backend,
            seki_backend_ets,
            seki_backend_pg,
            seki_limiter_registry,
            seki_pg_gossip
        ]},
        {<<"Advanced Patterns">>, [
            seki_adaptive,
            seki_shed,
            seki_hedge,
            seki_health
        ]},
        {<<"Instrumentation">>, [
            seki_otel
        ]}
    ]}
]}.
