%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-

{erl_opts, [
    debug_info,
    warnings_as_errors,
    warn_missing_spec,
    {feature, maybe_expr, enable}
]}.

{src_dirs, [{"src", [{recursive, true}]}]}.
{shell, [{config, "./config/dev_sys.config.src"}]}.

{deps, [
    %% Floor is 0.15.3, not 0.15: nova 0.15.1 crashes the connection process
    %% when a websocket controller replies with a list of frames, because
    %% nova_basic_handler:handle_ws/2 conses the payload onto the command list
    %% as one element and the whole list reaches cow_ws:frame/2 as a single
    %% frame (function_clause). Fixed in novaframework/nova#400, released in
    %% 0.15.3. Do not widen this to `~> 0.15`, which would let 0.15.1 back in.
    {nova, "~> 0.15.3"},
    {kura, "~> 2.20"},
    {kura_postgres, "~> 1.0"},
    {nova_auth, "~> 0.2"},
    {nova_auth_oidc, "~> 0.2"},
    {nova_resilience, "~> 1.0"},
    {luerl, "~> 1.5"},
    {seki, "~> 0.4"},
    {shigoto, "~> 1.9"}
]}.

{relx, [
    {release, {asobi, git}, [
        asobi,
        sasl
    ]},
    {mode, dev},
    {sys_config_src, "./config/dev_sys.config.src"},
    {vm_args_src, "./config/vm.args.src"}
]}.

{profiles, [
    {prod, [
        {relx, [
            {mode, prod},
            {sys_config_src, "./config/prod_sys.config.src"}
        ]}
    ]},
    {test, [
        %% nowarn_deprecated_catch: OTP 29 deprecates the `catch Expr` form; test
        %% teardown uses it for fire-and-forget cleanup (catch exit/2, meck:unload).
        %% Suppress in tests only - src is catch-free. (Migrate to try/catch later.)
        {erl_opts, [
            nowarn_export_all,
            nowarn_missing_spec,
            nowarn_deprecated_catch,
            warnings_as_errors,
            {i, "test"}
        ]},
        {deps, [
            {nova_test, {git, "https://github.com/novaframework/nova_test.git", {branch, "main"}}},
            {meck, "~> 1.2"},
            {proper, "~> 1.4"}
        ]},
        {ct_opts, [{sys_config, "./config/dev_sys.config.src"}]},
        %% EUnit's default per-test timeout is 5s, and a timeout kills the whole
        %% enclosing group's runner process - the remaining tests in that group
        %% are never run and the summary reads "N tests, 0 failures, M cancelled"
        %% with a total that shifts between runs (asobi #279). Several match and
        %% world tests legitimately sit within a second or two of that limit, so
        %% a loaded 2-core CI runner tips them over at random. Scale every
        %% timeout so wall-clock jitter can't be mistaken for a regression.
        {eunit_opts, [{scale_timeouts, 4}]},
        {extra_src_dirs, [{"test", [{recursive, true}]}]},
        {xref_extra_paths, ["test"]}
    ]}
]}.

{dialyzer, [
    {plt_apps, all_deps},
    {plt_extra_apps, [kura, inets, nova_auth, nova_auth_oidc]},
    {warnings, [unknown, unmatched_returns]},
    %% The `rebar3 asobi ...` providers run inside rebar3, against rebar3's own
    %% modules. Those are not deps of asobi and are absent from the PLT by
    %% construction.
    {exclude_mods, [rebar3_asobi_check, rebar3_asobi_console]}
]}.

{project_plugins, [
    {rebar3_nova, {git, "https://github.com/Taure/rebar3_nova.git", {branch, "feat/unified-gen"}}},
    {rebar3_kura, {git, "https://github.com/Taure/rebar3_kura.git", {tag, "v0.16.1"}}},
    {rebar3_audit, {git, "https://github.com/Taure/rebar3_audit.git", {tag, "v0.2.7"}}},
    {rebar3_sbom,
        {git, "https://github.com/Taure/rebar3_sbom.git", {branch, "feat/include-otp-components"}}},
    rebar3_ex_doc,
    covertool,
    {erlfmt, "~>1.7"}
]}.

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

%% Only `doc` belongs here. rebar3_hex reads the package's file list out of
%% src/asobi.app.src, not out of this key, so an `include_files` written here
%% is accepted by rebar3 and then ignored - which is how `console` came to be
%% listed for a release and shipped in none. It lives in the .app.src now.
{hex, [
    {doc, #{provider => ex_doc}}
]}.

{ex_doc, [
    {source_url, <<"https://github.com/widgrensit/asobi">>},
    {extras, [
        <<"README.md">>,
        <<"guides/getting-started.md">>,
        <<"guides/lua-scripting.md">>,
        <<"guides/lua-api.md">>,
        <<"guides/lua-bots.md">>,
        <<"guides/configuration.md">>,
        <<"guides/console.md">>,
        <<"guides/console-extensions.md">>,
        <<"guides/rest-api.md">>,
        <<"guides/websocket-protocol.md">>,
        <<"guides/matchmaking.md">>,
        <<"guides/lobbies.md">>,
        <<"guides/economy.md">>,
        <<"guides/testing-multiple-players.md">>,
        <<"guides/comparison.md">>,
        <<"guides/clustering.md">>,
        <<"guides/observability.md">>,
        <<"guides/authentication.md">>,
        <<"guides/iap.md">>,
        <<"guides/voting.md">>,
        <<"guides/world-server.md">>,
        <<"guides/large-worlds.md">>,
        <<"guides/performance-tuning.md">>,
        <<"guides/phases.md">>,
        <<"guides/self-hosting.md">>,
        <<"guides/cloud.md">>,
        <<"guides/extensions.md">>,
        <<"guides/security-threat-model.md">>,
        <<"guides/security-auth.md">>,
        <<"guides/security-known-limitations.md">>,
        <<"guides/security-sandbox.md">>,
        <<"guides/security-trust-model.md">>,
        <<"guides/security-lua-known-limitations.md">>,
        <<"guides/migrate-from-nakama.md">>,
        <<"guides/migrate-from-playfab.md">>,
        <<"guides/migrate-from-hathora.md">>,
        <<"guides/architecture.md">>,
        <<"guides/benchmarks.md">>,
        <<"guides/glossary.md">>,
        <<"guides/exit.md">>,
        <<"SECURITY.md">>,
        <<"CONTRIBUTING.md">>,
        <<"LICENSE">>
    ]},
    {groups_for_extras, [
        {<<"Getting Started">>, [
            <<"guides/getting-started.md">>,
            <<"guides/lua-scripting.md">>,
            <<"guides/lua-api.md">>,
            <<"guides/lua-bots.md">>,
            <<"guides/testing-multiple-players.md">>,
            <<"guides/comparison.md">>,
            <<"guides/glossary.md">>
        ]},
        {<<"Guides">>, [
            <<"guides/configuration.md">>,
            <<"guides/console.md">>,
            <<"guides/console-extensions.md">>,
            <<"guides/rest-api.md">>,
            <<"guides/websocket-protocol.md">>,
            <<"guides/matchmaking.md">>,
            <<"guides/lobbies.md">>,
            <<"guides/economy.md">>,
            <<"guides/clustering.md">>,
            <<"guides/observability.md">>,
            <<"guides/authentication.md">>,
            <<"guides/iap.md">>,
            <<"guides/voting.md">>,
            <<"guides/world-server.md">>,
            <<"guides/large-worlds.md">>,
            <<"guides/performance-tuning.md">>,
            <<"guides/phases.md">>,
            <<"guides/self-hosting.md">>,
            <<"guides/cloud.md">>,
            <<"guides/extensions.md">>
        ]},
        {<<"Migrating">>, [
            <<"guides/migrate-from-nakama.md">>,
            <<"guides/migrate-from-playfab.md">>,
            <<"guides/migrate-from-hathora.md">>,
            <<"guides/exit.md">>
        ]},
        {<<"Reference">>, [
            <<"guides/architecture.md">>,
            <<"guides/benchmarks.md">>
        ]},
        {<<"Security">>, [
            <<"guides/security-threat-model.md">>,
            <<"guides/security-auth.md">>,
            <<"guides/security-known-limitations.md">>,
            <<"guides/security-sandbox.md">>,
            <<"guides/security-trust-model.md">>,
            <<"guides/security-lua-known-limitations.md">>,
            <<"SECURITY.md">>
        ]}
    ]},
    {groups_for_modules, [
        {<<"Schemas">>, [
            asobi_player,
            asobi_player_stats,
            asobi_match_record,
            asobi_wallet,
            asobi_transaction,
            asobi_item_def,
            asobi_player_item,
            asobi_store_listing,
            asobi_friendship,
            asobi_group,
            asobi_group_member,
            asobi_chat_message,
            asobi_notification,
            asobi_tournament,
            asobi_cloud_save,
            asobi_storage,
            asobi_leaderboard_entry,
            asobi_player_identity,
            asobi_vote,
            asobi_ops_audit_entry
        ]},
        {<<"Controllers">>, [
            asobi_auth_controller,
            asobi_oauth_controller,
            asobi_iap_controller,
            asobi_player_controller,
            asobi_match_controller,
            asobi_matchmaker_controller,
            asobi_leaderboard_controller,
            asobi_economy_controller,
            asobi_inventory_controller,
            asobi_social_controller,
            asobi_chat_controller,
            asobi_tournament_controller,
            asobi_notification_controller,
            asobi_storage_controller,
            asobi_vote_controller
        ]},
        {<<"Ops">>, [
            asobi_ops_controller,
            asobi_ops_params,
            asobi_ops_page,
            asobi_ops_players,
            asobi_ops_matches,
            asobi_ops_features,
            asobi_ops_audit,
            asobi_ops_auth,
            asobi_ops_caps,
            asobi_ops_notifications
        ]},
        {<<"Console">>, [
            asobi_console,
            asobi_console_controller,
            asobi_console_csp,
            asobi_console_session,
            asobi_console_shell
        ]},
        {<<"Real-Time">>, [
            asobi_ws_handler,
            asobi_match_server,
            asobi_matchmaker,
            asobi_chat_channel,
            asobi_presence,
            asobi_player_session,
            asobi_vote_server
        ]},
        {<<"Auth">>, [
            asobi_oidc_config,
            asobi_steam,
            asobi_iap
        ]},
        {<<"Lua Runtime">>, [
            asobi_lua_loader,
            asobi_lua_match,
            asobi_lua_match_shared,
            asobi_lua_world,
            asobi_lua_api,
            asobi_lua_surface,
            asobi_lua_phases,
            asobi_lua_reload,
            asobi_lua_validate,
            asobi_lua_dev_errors,
            asobi_lua_game_error,
            asobi_lua_config,
            asobi_lua_config_watcher,
            asobi_lua_env,
            asobi_lua_sup
        ]},
        {<<"Bots">>, [
            asobi_bot,
            asobi_bot_spawner,
            asobi_bot_sup
        ]},
        {<<"Extensions">>, [
            asobi_extension,
            asobi_extensions,
            asobi_rpc,
            asobi_extension_sup,
            asobi_extension_child_sup,
            asobi_extension_watch,
            asobi_extension_reserved,
            asobi_readiness
        ]},
        {<<"Core">>, [
            asobi_app,
            asobi_sup,
            asobi_router,
            asobi_repo,
            asobi_error,
            asobi_player_erase,
            asobi_player_export,
            asobi_guest_reaper,
            asobi_economy,
            asobi_leaderboard_server,
            asobi_tournament_server
        ]}
    ]}
]}.

{erlfmt, [
    write,
    {files, [
        "rebar.config",
        "src/*.app.src",
        "src/**/{*.erl, *.hrl}",
        "test/**/{*.erl, *.hrl}"
    ]},
    {exclude_files, ["config/vm.args.src", "config/prod_sys.config.src"]}
]}.

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

%% rebar3's own API, called by `rebar3 asobi check` and only ever present when
%% rebar3 is the one running it.
{xref_ignores, [
    {providers, create, 1},
    {rebar_api, debug, 2},
    {rebar_api, error, 2},
    {rebar_api, info, 2},
    {rebar_api, warn, 2},
    {rebar_app_info, dir, 1},
    {rebar_app_info, ebin_dir, 1},
    {rebar_app_info, name, 1},
    {rebar_dir, base_dir, 1},
    {rebar_file_utils, cp_r, 2},
    {rebar_file_utils, rm_rf, 1},
    {rebar_state, add_provider, 2},
    {rebar_state, all_deps, 1},
    {rebar_state, command_parsed_args, 1},
    {rebar_state, get, 3},
    {rebar_state, project_apps, 1},
    {rebar_utils, sh, 2}
]}.
