src/lightspeed@release@policy.erl

-module(lightspeed@release@policy).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/lightspeed/release/policy.gleam").
-export([ga_1_0_0/0, version/1, deprecation/1, support/1, compatibility/1, matrix/1, matrix_signature/1, policy_signature/1, valid/1]).
-export_type([compatibility_target/0, deprecation_policy/0, support_policy/0, matrix_entry/0, release_policy/0]).

-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.

?MODULEDOC(" Stable API/deprecation/support policy for 1.0.0 GA.\n").

-type compatibility_target() :: {compatibility_target,
        binary(),
        binary(),
        binary(),
        integer(),
        integer()}.

-type deprecation_policy() :: {deprecation_policy,
        integer(),
        boolean(),
        boolean(),
        boolean()}.

-type support_policy() :: {support_policy,
        binary(),
        binary(),
        binary(),
        integer()}.

-type matrix_entry() :: {matrix_entry, binary(), binary(), binary()}.

-type release_policy() :: {release_policy,
        binary(),
        compatibility_target(),
        deprecation_policy(),
        support_policy(),
        list(matrix_entry())}.

-file("src/lightspeed/release/policy.gleam", 55).
?DOC(" 1.0.0 GA release policy.\n").
-spec ga_1_0_0() -> release_policy().
ga_1_0_0() ->
    {release_policy,
        <<"1.0.0"/utf8>>,
        {compatibility_target,
            <<"1.8.7"/utf8>>,
            <<"1.1.30"/utf8>>,
            <<"lightspeed"/utf8>>,
            1,
            1},
        {deprecation_policy, 2, true, true, true},
        {support_policy, <<"1.x"/utf8>>, <<"0.1.x"/utf8>>, <<"<0.1.0"/utf8>>, 1},
        [{matrix_entry,
                <<"M13"/utf8>>,
                <<"framework-compat"/utf8>>,
                <<"framework endpoint/controller/verified route fixtures"/utf8>>},
            {matrix_entry,
                <<"M14"/utf8>>,
                <<"channel-pubsub-presence"/utf8>>,
                <<"channel harness + channel fixture tests"/utf8>>},
            {matrix_entry,
                <<"M15"/utf8>>,
                <<"component-template-compat"/utf8>>,
                <<"stateful/template/story compatibility fixtures"/utf8>>},
            {matrix_entry,
                <<"M16"/utf8>>,
                <<"client-js-interop"/utf8>>,
                <<"client/lightspeed.test.js conformance suite"/utf8>>},
            {matrix_entry,
                <<"M17"/utf8>>,
                <<"liveview-test-dsl"/utf8>>,
                <<"lightspeed/testing/liveview deterministic fixtures"/utf8>>},
            {matrix_entry,
                <<"M18"/utf8>>,
                <<"generator-tooling"/utf8>>,
                <<"generator harness deterministic matrix"/utf8>>},
            {matrix_entry,
                <<"M19"/utf8>>,
                <<"data-migration"/utf8>>,
                <<"migration harness + scoped authz fixtures"/utf8>>}]}.

-file("src/lightspeed/release/policy.gleam", 118).
?DOC(" Policy version label.\n").
-spec version(release_policy()) -> binary().
version(Policy) ->
    erlang:element(2, Policy).

-file("src/lightspeed/release/policy.gleam", 123).
?DOC(" Deprecation policy accessor.\n").
-spec deprecation(release_policy()) -> deprecation_policy().
deprecation(Policy) ->
    erlang:element(4, Policy).

-file("src/lightspeed/release/policy.gleam", 128).
?DOC(" Support policy accessor.\n").
-spec support(release_policy()) -> support_policy().
support(Policy) ->
    erlang:element(5, Policy).

-file("src/lightspeed/release/policy.gleam", 133).
?DOC(" Compatibility target accessor.\n").
-spec compatibility(release_policy()) -> compatibility_target().
compatibility(Policy) ->
    erlang:element(3, Policy).

-file("src/lightspeed/release/policy.gleam", 138).
?DOC(" Frozen matrix accessor.\n").
-spec matrix(release_policy()) -> list(matrix_entry()).
matrix(Policy) ->
    erlang:element(6, Policy).

-file("src/lightspeed/release/policy.gleam", 211).
-spec join_with(binary(), list(binary())) -> binary().
join_with(Separator, Values) ->
    case Values of
        [] ->
            <<""/utf8>>;

        [Value] ->
            Value;

        [Value@1 | Rest] ->
            <<<<Value@1/binary, Separator/binary>>/binary,
                (join_with(Separator, Rest))/binary>>
    end.

-file("src/lightspeed/release/policy.gleam", 173).
?DOC(" Stable matrix signature.\n").
-spec matrix_signature(list(matrix_entry())) -> binary().
matrix_signature(Entries) ->
    Labels = gleam@list:map(
        Entries,
        fun(Entry) ->
            <<<<<<<<(erlang:element(2, Entry))/binary, ":"/utf8>>/binary,
                        (erlang:element(3, Entry))/binary>>/binary,
                    ":"/utf8>>/binary,
                (erlang:element(4, Entry))/binary>>
        end
    ),
    join_with(<<";"/utf8>>, Labels).

-file("src/lightspeed/release/policy.gleam", 193).
-spec support_signature(support_policy()) -> binary().
support_signature(Policy) ->
    <<<<<<<<<<<<<<"ga_line="/utf8, (erlang:element(2, Policy))/binary>>/binary,
                            ",maintenance_line="/utf8>>/binary,
                        (erlang:element(3, Policy))/binary>>/binary,
                    ",eol_line="/utf8>>/binary,
                (erlang:element(4, Policy))/binary>>/binary,
            ",min_protocol="/utf8>>/binary,
        (erlang:integer_to_binary(erlang:element(5, Policy)))/binary>>.

-file("src/lightspeed/release/policy.gleam", 204).
-spec bool_label(boolean()) -> binary().
bool_label(Value) ->
    case Value of
        true ->
            <<"true"/utf8>>;

        false ->
            <<"false"/utf8>>
    end.

-file("src/lightspeed/release/policy.gleam", 182).
-spec deprecation_signature(deprecation_policy()) -> binary().
deprecation_signature(Policy) ->
    <<<<<<<<<<<<<<"warn_releases="/utf8,
                                (erlang:integer_to_binary(
                                    erlang:element(2, Policy)
                                ))/binary>>/binary,
                            ",major_required="/utf8>>/binary,
                        (bool_label(erlang:element(3, Policy)))/binary>>/binary,
                    ",migration_notes="/utf8>>/binary,
                (bool_label(erlang:element(4, Policy)))/binary>>/binary,
            ",rfc_adr="/utf8>>/binary,
        (bool_label(erlang:element(5, Policy)))/binary>>.

-file("src/lightspeed/release/policy.gleam", 143).
?DOC(" Stable policy signature for reproducible GA checks.\n").
-spec policy_signature(release_policy()) -> binary().
policy_signature(Policy) ->
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"ga="/utf8,
                                                                        (erlang:element(
                                                                            2,
                                                                            Policy
                                                                        ))/binary>>/binary,
                                                                    "|phoenix="/utf8>>/binary,
                                                                (erlang:element(
                                                                    2,
                                                                    erlang:element(
                                                                        3,
                                                                        Policy
                                                                    )
                                                                ))/binary>>/binary,
                                                            "|liveview="/utf8>>/binary,
                                                        (erlang:element(
                                                            3,
                                                            erlang:element(
                                                                3,
                                                                Policy
                                                            )
                                                        ))/binary>>/binary,
                                                    "|protocol="/utf8>>/binary,
                                                (erlang:element(
                                                    4,
                                                    erlang:element(3, Policy)
                                                ))/binary>>/binary,
                                            ":"/utf8>>/binary,
                                        (erlang:integer_to_binary(
                                            erlang:element(
                                                5,
                                                erlang:element(3, Policy)
                                            )
                                        ))/binary>>/binary,
                                    "|patch_stream="/utf8>>/binary,
                                (erlang:integer_to_binary(
                                    erlang:element(6, erlang:element(3, Policy))
                                ))/binary>>/binary,
                            "|deprecation="/utf8>>/binary,
                        (deprecation_signature(erlang:element(4, Policy)))/binary>>/binary,
                    "|support="/utf8>>/binary,
                (support_signature(erlang:element(5, Policy)))/binary>>/binary,
            "|matrix="/utf8>>/binary,
        (matrix_signature(erlang:element(6, Policy)))/binary>>.

-file("src/lightspeed/release/policy.gleam", 165).
?DOC(" True when policy aligns with runtime/package freeze constraints.\n").
-spec valid(release_policy()) -> boolean().
valid(Policy) ->
    Expected = ga_1_0_0(),
    (policy_signature(Policy) =:= policy_signature(Expected)) andalso (erlang:element(
        2,
        Policy
    )
    =:= <<"1.0.0"/utf8>>).