%% -*- 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_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_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"}},
        {"CHANGELOG.md", #{title => "Changelog"}},
        {"LICENSE", #{title => "License"}},
        {"docs/GLOSSARY.md", #{title => "Glossary"}},
        %% Feature Guides
        {"docs/guides/PUBSUB_GUIDE.md", #{title => "PubSub Guide"}},
        {"docs/guides/RPC_GUIDE.md", #{title => "RPC Guide"}},
        {"docs/guides/DIST_OVER_MESH_GUIDE.md", #{title => "Distribution Over Mesh"}},
        {"docs/guides/CLUSTERING_GUIDE.md", #{title => "Clustering"}},
        {"docs/guides/CONTENT_TRANSFER_GUIDE.md", #{title => "Content Transfer"}},
        {"docs/guides/DHT_GUIDE.md", #{title => "DHT Architecture"}},

        {"docs/guides/AUTHORIZATION_GUIDE.md", #{title => "Authorization (UCAN/DID)"}},
        {"docs/guides/PROTOCOL_GATEKEEPER_GUIDE.md", #{title => "Protocol Gatekeeper"}},
        {"docs/guides/MRI_GUIDE.md", #{title => "MRI (Resource Identifiers)"}},
        {"docs/guides/DEVELOPMENT.md", #{title => "Development 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/TLS_GUIDE.md", #{title => "TLS Setup"}},
        {"docs/operator/MDNS_SETUP.md", #{title => "mDNS Setup (Optional)"}},
        %% Architecture
        {"docs/guides/FULL_SUPERVISION_TREE.md", #{title => "Supervision Tree"}},
        {"docs/ROADMAP.md", #{title => "Roadmap"}}
    ]},
    {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 federated relay mesh, 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"
    ]}
]}.
