%% -*- 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_bridge_system",
    "src/macula_dist_system",
    "src/macula_gateway_system",
    "src/macula_nat_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"},

    %% mDNS local discovery (optional - hex.pm package)
    {macula_mdns, "0.1.0"},

    %% Telemetry for observability and metrics
    {telemetry, "1.3.0"}

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

    %% Note: Authorization (v0.17.0+) uses inline Erlang implementations
    %% for DID parsing and UCAN validation - no external NIF dependency

    %% Note: Ra/Raft was removed in v0.14.0
    %% Macula uses CRDTs (macula_crdt.erl) for masterless state management
    %% See architecture/ROADMAP.md for details
]}.

{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_bridge_system"},
    {dir, "test/macula_dist_system"},
    {dir, "test/macula_gateway_system"},
    {dir, "test/macula_nat_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.17.1"}, [
        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_dist_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"}},
        {"GETTING_STARTED.md", #{title => "Getting Started"}},
        {"ARCHITECTURE.md", #{title => "Architecture Guide"}},
        {"CHANGELOG.md", #{title => "Changelog"}},
        {"LICENSE", #{title => "License"}},
        %% Business Documentation
        {"docs/business/OVERVIEW.md", #{title => "Platform Overview"}},
        {"docs/business/MOTIVATION.md", #{title => "Why Macula"}},
        {"docs/business/WHY_DECENTRALIZED.md", #{title => "Why Decentralized"}},
        {"docs/business/USE_CASES.md", #{title => "Use Cases"}},
        {"docs/business/COMPARISON.md", #{title => "Technology Comparison"}},
        {"docs/GLOSSARY.md", #{title => "Glossary"}},
        %% Comparisons
        {"docs/comparisons/README.md", #{title => "Comparisons"}},
        {"docs/comparisons/VS_DISTRIBUTED_ERLANG.md", #{title => "vs Distributed Erlang"}},
        %% User Guides
        {"docs/user/QUICK_START.md", #{title => "Quick Start"}},
        {"docs/user/HELLO_WORLD.md", #{title => "Hello World"}},
        %% Developer Guides
        {"docs/developer/DEVELOPMENT.md", #{title => "Development Guide"}},
        {"docs/developer/RPC_GUIDE.md", #{title => "RPC Guide"}},
        {"docs/developer/PUBSUB_GUIDE.md", #{title => "PubSub Guide"}},
        %% Operator Guides
        {"docs/operator/PERFORMANCE_GUIDE.md", #{title => "Performance Guide"}},
        {"docs/operator/MONITORING_GUIDE.md", #{title => "Monitoring Guide"}},
        {"docs/operator/TROUBLESHOOTING_GUIDE.md", #{title => "Troubleshooting"}},
        {"docs/operator/MDNS_SETUP.md", #{title => "mDNS Setup (Optional)"}},
        %% Deep-Dive Guides
        {"docs/guides/DHT_GUIDE.md", #{title => "DHT Architecture"}},
        {"docs/guides/NAT_TYPES_EXPLAINED.md", #{title => "NAT Types"}},
        {"docs/guides/NAT_TRAVERSAL_DEVELOPER_GUIDE.md", #{title => "NAT Traversal"}},
        {"docs/guides/AUTHORIZATION_GUIDE.md", #{title => "Authorization (UCAN/DID)"}},
        %% Architecture Deep Dives
        {"architecture/FULL_SUPERVISION_TREE.md", #{title => "Supervision Tree"}},
        {"architecture/MACULA_PROJECT_STRUCTURE.md", #{title => "Project Structure"}},
        {"architecture/INDEX.md", #{title => "Architecture Index"}},
        %% Roadmap and Planning
        {"architecture/ROADMAP.md", #{title => "Roadmap"}},
        %% MRI System Guide
        {"docs/guides/MRI_GUIDE.md", #{title => "MRI (Resource Identifiers)"}}
    ]},
    {main, "overview"},
    {source_url, "https://github.com/macula-io/macula"},
    {assets, #{"assets" => "assets"}},
    {logo, "artwork/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 NAT traversal (hole-punch, relay), Pub/Sub, async RPC, Kademlia DHT, hierarchical Bridge mesh for fractal network topology"},
    {files, [
        "src",
        "include",
        "rebar.config",
        "rebar.lock",
        "README.md",
        "CHANGELOG.md",
        "LICENSE",
        "assets",
        "artwork",
        "docs",
        "architecture"
    ]}
]}.
