%% -*- mode: erlang -*-
%% Macula HTTP/3 Mesh - Root Rebar3 Configuration

{erl_opts, [
    debug_info,
    warnings_as_errors,
    warn_export_vars,
    warn_unused_vars,
    warn_obsolete_guard
]}.

%% Include subdirectories in src/ for compilation
{src_dirs, [
    "src",
    "src/macula_bootstrap_system",
    "src/macula_gateway_system",
    "src/macula_peer_system",
    "src/macula_pubsub_system",
    "src/macula_rpc_system",
    "src/macula_routing_system",
    "src/macula_membership_system",
    "src/macula_platform_system"
]}.

{deps, [
    %% QUIC transport (using Hex for publishable packages)
    {quicer, "0.2.15"},

    %% MessagePack serialization
    {msgpack, "0.8.1"},

    %% Process registry
    {gproc, "0.9.1"},

    %% Raft consensus for distributed coordination
    {ra, "2.17.1"}

    %% JSON encoding: Using built-in json module (OTP 27+)
]}.

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

%% Test configuration
{eunit_opts, [
    verbose,
    {dir, "test"},  %% Top-level tests
    {dir, "test/macula_bootstrap_system"},
    {dir, "test/macula_gateway_system"},
    {dir, "test/macula_peer_system"},
    {dir, "test/macula_pubsub_system"},
    {dir, "test/macula_rpc_system"},
    {dir, "test/macula_routing_system"},
    {dir, "test/macula_membership_system"},
    {dir, "test/macula_platform_system"}
]}.

{cover_enabled, true}.
{cover_opts, [verbose]}.
{cover_excl_mods, []}.  %% Modules to exclude from coverage (e.g., generated code)
{cover_print_enabled, true}.
{cover_export_enabled, true}.

{ct_opts, [
    {sys_config, "config/test.sys.config"}
]}.

{dialyzer, [
    {warnings, [
        no_return,
        no_unused,
        no_improper_lists,
        no_fun_app,
        no_match,
        no_opaque,
        no_fail_call,
        error_handling
    ]},
    {plt_apps, top_level_deps},
    {plt_extra_apps, []},
    {plt_location, local},
    {base_plt_apps, [erts, kernel, stdlib, crypto, public_key, ssl]},
    {base_plt_location, global}
]}.

%% Shell configuration
{shell, [
    {apps, [macula]},
    {config, "config/sys.config"}
]}.

%% Release configuration
{relx, [
    {release, {macula, "0.9.2"}, [
        macula,
        sasl,
        runtime_tools
        %% observer - removed for headless deployments (requires wx/OpenGL)
    ]},

    {mode, dev},
    {include_erts, true},
    {extended_start_script, true},

    {sys_config, "./config/sys.config"},
    {vm_args, "./config/vm.args"},

    {overlay, [
        {mkdir, "log"},
        {mkdir, "data"},
        {copy, "README.md", "README.md"},
        {copy, "LICENSE", "LICENSE"}
    ]}
]}.

%% Profiles
{profiles, [
    {test, [
        {deps, [
            {proper, "1.4.0"},
            {meck, "0.9.2"}
        ]},
        {erl_opts, [nowarn_export_all]},
        {extra_src_dirs, [
            "test",
            "test/macula_bootstrap_system",
            "test/macula_gateway_system",
            "test/macula_peer_system",
            "test/macula_pubsub_system",
            "test/macula_rpc_system",
            "test/macula_routing_system",
            "test/macula_membership_system",
            "test/macula_platform_system",
            "test/e2e",
            "test/integration"
        ]}
    ]},

    {prod, [
        {erl_opts, [
            no_debug_info,
            deterministic
        ]},
        {relx, [
            {mode, prod},
            {dev_mode, false},
            {include_src, false}
        ]}
    ]},

    {lint, [
        {plugins, [
            {rebar3_lint, "3.2.5"}
        ]}
    ]}
]}.

%% Documentation
{ex_doc, [
    {extras, [
        {"README.md", #{title => "Overview"}},
        {"architecture/PLATFORM_VISION.md", #{title => "Platform Vision"}},
        {"GETTING_STARTED.md", #{title => "Getting Started"}},
        {"ARCHITECTURE.md", #{title => "Architecture Guide"}},
        {"CHANGELOG.md", #{title => "Changelog"}},
        {"architecture/MIGRATION_V0.8.4_TO_V0.8.5.md", #{title => "Migration Guide v0.8.5"}},
        {"TODO.md", #{title => "Known Issues & Roadmap"}},
        {"LICENSE", #{title => "License"}},
        {"architecture/FULL_SUPERVISION_TREE.md", #{title => "Supervision Tree"}},
        {"architecture/v0.8.0-OVERVIEW.md", #{title => "v0.8.0 Release Overview"}},
        {"architecture/v0.8.0-CHANGELOG.md", #{title => "v0.8.0 Detailed Changelog"}},
        {"architecture/v0.8.0-ROADMAP.md", #{title => "Roadmap (v0.9.1 History + v0.10.0 Planning)"}},
        {"architecture/v1.0.0-ROADMAP.md", #{title => "v1.0.0 Roadmap"}},
        {"architecture/MESH_HOT_UPGRADE.md", #{title => "Mesh Hot Upgrade Design"}},
        {"architecture/INDEX.md", #{title => "Architecture Index"}},
        {"architecture/MACULA_PROJECT_STRUCTURE.md", #{title => "Project Structure"}},
        {"docs/KADEMLIA_DHT_ARCHITECTURE.md", #{title => "Kademlia DHT"}},
        {"docs/DEVELOPMENT.md", #{title => "Development Guide"}}
    ]},
    {main, "readme"},
    {source_url, "https://github.com/macula-io/macula"},
    {assets, #{"artwork" => "assets"}},
    {logo, "artwork/macula-alt-logo.svg"},
    {prefix_ref_vsn_with_v, false}
]}.

%% Hex package configuration
{hex, [
    {doc, #{provider => ex_doc}},
    {licenses, ["Apache-2.0"]},
    {links, #{
        <<"GitHub">> => <<"https://github.com/macula-io/macula">>,
        <<"Documentation">> => <<"https://hexdocs.pm/macula">>,
        <<"Changelog">> => <<"https://github.com/macula-io/macula/blob/main/CHANGELOG.md">>
    }},
    {description, "HTTP/3 mesh networking platform with Pub/Sub, RPC, and Kademlia DHT featuring Platform Layer with Raft-based distributed coordination, CRDT support (LWW-Register), and comprehensive test coverage"},
    {files, [
        "src",
        "include",
        "rebar.config",
        "rebar.lock",
        "README.md",
        "CHANGELOG.md",
        "TODO.md",
        "LICENSE",
        "artwork",
        "docs",
        "architecture"
    ]}
]}.
