{erl_opts, [
    debug_info,
    warnings_as_errors
]}.

{deps, [
    {khepri, "0.17.2"},
    {telemetry, "1.3.0"},
    {reckon_gater, "~> 3.1"}
]}.

%% Build the embedded Rust NIFs from native/<crate>/ into priv/<crate>.so
%% before rebar3 compiles Erlang. The script is idempotent (skips
%% already-built .so files) and tolerates a missing Rust toolchain
%% (logs warning and continues — reckon-db's wrapper modules will
%% just use the Erlang fallbacks). See priv/build-nifs.sh for details.
{pre_hooks, [
    {compile, "sh -c 'B=\"${REBAR_DEPS_DIR}/reckon_db\"; [ -f \"$B/priv/build-nifs.sh\" ] || B=\".\"; sh \"$B/priv/build-nifs.sh\" \"$B\"'"}
]}.

{project_plugins, [
    rebar3_proper,
    rebar3_ex_doc,
    rebar3_hex
]}.

{profiles, [
    {test, [
        {deps, [
            {proper, "1.4.0"},
            {meck, "0.9.2"}
        ]},
        {erl_opts, [
            debug_info,
            nowarn_export_all
        ]},
        {extra_src_dirs, [
            "test/unit",
            "test/integration",
            "test/support",
            "test/e2e"
        ]}
    ]},
    {prod, [
        {erl_opts, [
            no_debug_info,
            deterministic
        ]},
        {relx, [
            {release, {reckon_db, "1.0.0"}, [
                reckon_db,
                sasl
            ]},
            {dev_mode, false},
            {include_erts, true},
            {extended_start_script, true},
            {sys_config, "config/sys.config"},
            {vm_args, "config/vm.args"}
        ]}
    ]}
]}.

{shell, [
    {apps, [reckon_db]}
]}.

{relx, [
    {release, {reckon_db, "1.0.0"}, [
        reckon_db,
        sasl
    ]},
    {dev_mode, true},
    {include_erts, false},
    {extended_start_script, true},
    {sys_config, "config/sys.config"},
    {vm_args, "config/vm.args"}
]}.

%% EUnit configuration
{eunit_opts, [
    verbose,
    {report, {eunit_surefire, [{dir, "_build/test/reports"}]}}
]}.

%% Common Test configuration
{ct_opts, [
    {dir, "test/integration"},
    {sys_config, "config/test.config"}
]}.

%% Cover configuration
{cover_enabled, true}.
{cover_opts, [verbose]}.

%% Dialyzer configuration
{dialyzer, [
    {warnings, [
        unknown,
        unmatched_returns,
        error_handling,
        underspecs
    ]},
    {plt_apps, top_level_deps},
    {plt_extra_apps, [kernel, stdlib, crypto]}
]}.

%% Ex_doc configuration
{ex_doc, [
    {extras, [
        {"README.md", #{title => <<"Readme">>}},
        {"LICENSE", #{title => <<"License">>}},
        {"CHANGELOG.md", #{title => <<"Changelog">>}},
        %% Core Concepts
        {"guides/event_sourcing_paradigms.md", #{title => <<"Event Sourcing Paradigms">>}},
        {"guides/event_sourcing.md", #{title => <<"Event Sourcing">>}},
        {"guides/cqrs.md", #{title => <<"CQRS">>}},
        {"guides/subscriptions.md", #{title => <<"Subscriptions">>}},
        {"guides/snapshots.md", #{title => <<"Snapshots">>}},
        %% Advanced Features
        {"guides/temporal_queries.md", #{title => <<"Temporal Queries">>}},
        {"guides/scavenging.md", #{title => <<"Scavenging">>}},
        {"guides/stream_links.md", #{title => <<"Stream Links">>}},
        {"guides/dcb.md", #{title => <<"Dynamic Consistency Boundaries">>}},
        {"guides/dcb_raft_design.md", #{title => <<"DCB: Raft Design">>}},
        {"guides/schema_evolution.md", #{title => <<"Schema Evolution">>}},
        %% Operations
        {"guides/configuration.md", #{title => <<"Configuration">>}},
        {"guides/memory_pressure.md", #{title => <<"Memory Pressure">>}},
        {"guides/storage_internals.md", #{title => <<"Storage Internals">>}},
        {"guides/cluster_consistency.md", #{title => <<"Cluster Consistency">>}},
        {"guides/store_inspector.md", #{title => <<"Store Inspector">>}},
        %% Project policies
        {"docs/genai-policy.md", #{title => <<"Generative AI Policy">>}}
    ]},
    %% CHANGELOG entries legitimately reference historic internal
    %% functions that are private/hidden in the current code — those
    %% references are documenting what was fixed, not pointing readers
    %% at API surface. Suppress autolink warnings for that file only.
    {skip_undefined_reference_warnings_on, ["CHANGELOG.md"]},
    {main, <<"README.md">>},
    {source_url, <<"https://codeberg.org/reckon-db-org/reckon-db">>},
    {assets, #{<<"assets">> => <<"assets">>}}
]}.

%% Hex configuration.
%%
%% Package metadata (description, licenses, links, files) lives in
%% `src/reckon_db.app.src` — that's where rebar3_hex reads it from.
%% A `{files, [...]}` here is silently ignored, as v2.3.0 found out
%% the hard way.
{hex, [
    {doc, #{provider => ex_doc}}
]}.
