src/lightspeed@transport@progressive_enhancement.erl

-module(lightspeed@transport@progressive_enhancement).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/lightspeed/transport/progressive_enhancement.gleam").
-export([default_policy/0, fallback_first_policy/0, bidirectional_mutation_policy/0, default_proxy_headers/0, assess_proxy_headers/2, upgrade/3, proxy_assessment_signature/1, connect/6, downgrade/3, apply_increment/2, protocol_invariant_signature/1, run_degraded_workflows/2, transition_signature/1, capability_signature/1, proxy_assessment/1, mode_label/1, transport_label/1, workflow_signature/1, workflow_equivalence_signature/1]).
-export_type([mode_preference/0, negotiation_policy/0, proxy_headers/0, proxy_assessment/0, negotiated_state/0, connect_result/0, mutation_result/0, workflow_report/0, navigation_msg/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(" Transport compatibility negotiation and progressive enhancement expansion for M56.\n").

-type mode_preference() :: prefer_primary | prefer_fallback.

-type negotiation_policy() :: {negotiation_policy,
        mode_preference(),
        boolean(),
        boolean()}.

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

-type proxy_assessment() :: {proxy_assessment, boolean(), list(binary())}.

-opaque negotiated_state() :: {negotiated_state,
        lightspeed@transport@matrix:adapter_state(),
        lightspeed@transport@matrix:profile(),
        negotiation_policy(),
        integer(),
        list(binary()),
        proxy_assessment()}.

-type connect_result() :: {connected, negotiated_state(), list(binary())} |
    {rejected, lightspeed@transport@contract:adapter_error()}.

-type mutation_result() :: {mutation_result,
        negotiated_state(),
        binary(),
        integer(),
        binary()}.

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

-type navigation_msg() :: navigation_noop.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 91).
?DOC(" Default M56 policy.\n").
-spec default_policy() -> negotiation_policy().
default_policy() ->
    {negotiation_policy, prefer_primary, true, false}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 100).
?DOC(" Fallback-first policy for degraded-path certification.\n").
-spec fallback_first_policy() -> negotiation_policy().
fallback_first_policy() ->
    {negotiation_policy, prefer_fallback, true, false}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 109).
?DOC(" Bidirectional mutation policy used for explicit upgrade checks.\n").
-spec bidirectional_mutation_policy() -> negotiation_policy().
bidirectional_mutation_policy() ->
    {negotiation_policy, prefer_fallback, true, true}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 118).
?DOC(" Default trusted proxy headers.\n").
-spec default_proxy_headers() -> proxy_headers().
default_proxy_headers() ->
    {proxy_headers,
        <<"https"/utf8>>,
        <<"upgrade"/utf8>>,
        <<"websocket"/utf8>>,
        <<"203.0.113.10"/utf8>>,
        <<"req-m56-default"/utf8>>}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 581).
-spec append(list(TKO), list(TKO)) -> list(TKO).
append(Left, Right) ->
    case Left of
        [] ->
            Right;

        [Value | Rest] ->
            [Value | append(Rest, Right)]
    end.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 570).
-spec maybe_warn(list(binary()), boolean(), binary()) -> list(binary()).
maybe_warn(Warnings, Enabled, Warning) ->
    case Enabled of
        true ->
            append(Warnings, [Warning]);

        false ->
            Warnings
    end.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 129).
?DOC(" Stable proxy guidance assessment.\n").
-spec assess_proxy_headers(proxy_headers(), negotiation_policy()) -> proxy_assessment().
assess_proxy_headers(Headers, Policy) ->
    Require_upgrade = (erlang:element(2, Policy) =:= prefer_primary) orelse erlang:element(
        4,
        Policy
    ),
    Proto = string:lowercase(erlang:element(2, Headers)),
    Connection = string:lowercase(erlang:element(3, Headers)),
    Upgrade = string:lowercase(erlang:element(4, Headers)),
    Proto_ok = (Proto =:= <<"https"/utf8>>) orelse (Proto =:= <<"http"/utf8>>),
    Upgrade_ok = case Require_upgrade of
        true ->
            gleam_stdlib:contains_string(Connection, <<"upgrade"/utf8>>) andalso (Upgrade
            =:= <<"websocket"/utf8>>);

        false ->
            true
    end,
    Warnings = begin
        _pipe = [],
        _pipe@1 = maybe_warn(
            _pipe,
            erlang:element(5, Headers) =:= <<""/utf8>>,
            <<"forwarded_for_missing"/utf8>>
        ),
        _pipe@2 = maybe_warn(
            _pipe@1,
            erlang:element(6, Headers) =:= <<""/utf8>>,
            <<"request_id_missing"/utf8>>
        ),
        maybe_warn(
            _pipe@2,
            not Require_upgrade,
            <<"upgrade_header_not_required"/utf8>>
        )
    end,
    {proxy_assessment, Proto_ok andalso Upgrade_ok, Warnings}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 462).
-spec record_transition(negotiated_state(), binary()) -> negotiated_state().
record_transition(State, Entry) ->
    {negotiated_state,
        erlang:element(2, State),
        erlang:element(3, State),
        erlang:element(4, State),
        erlang:element(5, State),
        [Entry | erlang:element(6, State)],
        erlang:element(7, State)}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 455).
-spec preference_prefers_fallback(mode_preference()) -> boolean().
preference_prefers_fallback(Preference) ->
    case Preference of
        prefer_primary ->
            false;

        prefer_fallback ->
            true
    end.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 422).
-spec reconnect_with_preference(
    negotiated_state(),
    lightspeed@transport@matrix:connect_request(),
    lightspeed@transport@contract:auth_hook(),
    mode_preference(),
    binary()
) -> connect_result().
reconnect_with_preference(
    State,
    Request,
    Auth_hook,
    Preference,
    Transition_name
) ->
    case lightspeed@transport@matrix:reconnect(
        erlang:element(2, State),
        {connect_request,
            erlang:element(2, Request),
            erlang:element(3, Request),
            erlang:element(4, Request),
            erlang:element(5, Request),
            preference_prefers_fallback(Preference)},
        Auth_hook
    ) of
        {rejected, Error} ->
            {rejected, Error};

        {connected, Next_adapter, Frames} ->
            {connected,
                record_transition(
                    {negotiated_state,
                        Next_adapter,
                        erlang:element(3, State),
                        erlang:element(4, State),
                        erlang:element(5, State),
                        erlang:element(6, State),
                        erlang:element(7, State)},
                    <<<<<<<<Transition_name/binary, ":"/utf8>>/binary,
                                (lightspeed@transport@matrix:mode_label(
                                    Next_adapter
                                ))/binary>>/binary,
                            ":"/utf8>>/binary,
                        (lightspeed@transport@matrix:active_transport_label(
                            Next_adapter
                        ))/binary>>
                ),
                Frames}
    end.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 202).
?DOC(" Explicitly upgrade to primary realtime mode.\n").
-spec upgrade(
    negotiated_state(),
    lightspeed@transport@matrix:connect_request(),
    lightspeed@transport@contract:auth_hook()
) -> connect_result().
upgrade(State, Request, Auth_hook) ->
    reconnect_with_preference(
        State,
        Request,
        Auth_hook,
        prefer_primary,
        <<"upgrade"/utf8>>
    ).

-file("src/lightspeed/transport/progressive_enhancement.gleam", 374).
-spec ensure_bidirectional_mode(
    negotiated_state(),
    lightspeed@transport@matrix:connect_request(),
    lightspeed@transport@contract:auth_hook(),
    list(binary())
) -> connect_result().
ensure_bidirectional_mode(State, Request, Auth_hook, Frames) ->
    Needs_upgrade = erlang:element(4, erlang:element(4, State)) andalso not lightspeed@transport@matrix:capability_enabled(
        erlang:element(2, State),
        bidirectional_channel
    ),
    case Needs_upgrade of
        false ->
            {connected, State, Frames};

        true ->
            case erlang:element(3, erlang:element(4, State)) of
                false ->
                    {connected,
                        record_transition(
                            State,
                            <<"upgrade_skipped:policy_disabled"/utf8>>
                        ),
                        Frames};

                true ->
                    case upgrade(
                        State,
                        {connect_request,
                            erlang:element(2, Request),
                            erlang:element(3, Request),
                            erlang:element(4, Request),
                            erlang:element(5, Request) + 1,
                            erlang:element(6, Request)},
                        Auth_hook
                    ) of
                        {rejected, Error} ->
                            {connected,
                                record_transition(
                                    State,
                                    <<"upgrade_failed:"/utf8,
                                        (lightspeed@transport@contract:error_to_string(
                                            Error
                                        ))/binary>>
                                ),
                                Frames};

                        {connected, Upgraded, Upgrade_frames} ->
                            {connected,
                                Upgraded,
                                append(Frames, Upgrade_frames)}
                    end
            end
    end.

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

        [First | Rest] ->
            gleam@list:fold(
                Rest,
                First,
                fun(Accumulator, Value) ->
                    <<<<Accumulator/binary, Separator/binary>>/binary,
                        Value/binary>>
                end
            )
    end.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 588).
-spec bool_label(boolean()) -> binary().
bool_label(Value) ->
    case Value of
        true ->
            <<"true"/utf8>>;

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

-file("src/lightspeed/transport/progressive_enhancement.gleam", 318).
?DOC(" Stable proxy assessment signature.\n").
-spec proxy_assessment_signature(proxy_assessment()) -> binary().
proxy_assessment_signature(Assessment) ->
    <<<<<<"accepted="/utf8, (bool_label(erlang:element(2, Assessment)))/binary>>/binary,
            ":warnings="/utf8>>/binary,
        (join_with(<<","/utf8>>, erlang:element(3, Assessment)))/binary>>.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 152).
?DOC(" Connect and negotiate initial transport mode.\n").
-spec connect(
    lightspeed@agent@session:session(),
    lightspeed@transport@matrix:connect_request(),
    lightspeed@transport@matrix:profile(),
    lightspeed@transport@contract:auth_hook(),
    negotiation_policy(),
    proxy_headers()
) -> connect_result().
connect(Session_state, Request, Profile, Auth_hook, Policy, Proxy_headers) ->
    Assessment = assess_proxy_headers(Proxy_headers, Policy),
    case erlang:element(2, Assessment) of
        false ->
            {rejected,
                {protection_rejected,
                    <<"proxy_guidance_rejected:"/utf8,
                        (proxy_assessment_signature(Assessment))/binary>>}};

        true ->
            case lightspeed@transport@matrix:connect(
                Session_state,
                {connect_request,
                    erlang:element(2, Request),
                    erlang:element(3, Request),
                    erlang:element(4, Request),
                    erlang:element(5, Request),
                    preference_prefers_fallback(erlang:element(2, Policy))},
                Profile,
                Auth_hook
            ) of
                {rejected, Error} ->
                    {rejected, Error};

                {connected, Adapter, Frames} ->
                    State = {negotiated_state,
                        Adapter,
                        Profile,
                        Policy,
                        0,
                        [<<<<<<"connected:"/utf8,
                                        (lightspeed@transport@matrix:mode_label(
                                            Adapter
                                        ))/binary>>/binary,
                                    ":"/utf8>>/binary,
                                (lightspeed@transport@matrix:active_transport_label(
                                    Adapter
                                ))/binary>>],
                        Assessment},
                    ensure_bidirectional_mode(State, Request, Auth_hook, Frames)
            end
    end.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 211).
?DOC(" Explicitly downgrade to fallback polling mode when profile allows it.\n").
-spec downgrade(
    negotiated_state(),
    lightspeed@transport@matrix:connect_request(),
    lightspeed@transport@contract:auth_hook()
) -> connect_result().
downgrade(State, Request, Auth_hook) ->
    reconnect_with_preference(
        State,
        Request,
        Auth_hook,
        prefer_fallback,
        <<"downgrade"/utf8>>
    ).

-file("src/lightspeed/transport/progressive_enhancement.gleam", 559).
-spec frame_label(binary()) -> binary().
frame_label(Frame) ->
    case lightspeed@protocol:decode(Frame) of
        {ok, {hello, _, _}} ->
            <<"hello"/utf8>>;

        {ok, {diff, _, _}} ->
            <<"diff"/utf8>>;

        {ok, {ack, _}} ->
            <<"ack"/utf8>>;

        {ok, {event, _, Name, _}} ->
            <<"event:"/utf8, Name/binary>>;

        {ok, {failure, _, Reason}} ->
            <<"failure:"/utf8, Reason/binary>>;

        {error, Error} ->
            <<"decode_error:"/utf8,
                (lightspeed@protocol:decode_error_to_string(Error))/binary>>
    end.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 555).
-spec normalized_frame_labels(list(binary())) -> binary().
normalized_frame_labels(Frames) ->
    join_with(<<","/utf8>>, gleam@list:map(Frames, fun frame_label/1)).

-file("src/lightspeed/transport/progressive_enhancement.gleam", 535).
-spec drain_receive(lightspeed@transport@matrix:receive_result()) -> {lightspeed@transport@matrix:adapter_state(),
    list(binary())}.
drain_receive(Received) ->
    Polled = lightspeed@transport@matrix:poll(erlang:element(2, Received)),
    {erlang:element(2, Polled),
        append(erlang:element(3, Received), erlang:element(3, Polled))}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 542).
-spec prepare_adapter_for_mutation(
    lightspeed@transport@matrix:adapter_state(),
    integer()
) -> lightspeed@transport@matrix:adapter_state().
prepare_adapter_for_mutation(Adapter, Last_client_sequence) ->
    case Last_client_sequence =:= 0 of
        true ->
            Drained = lightspeed@transport@matrix:poll(Adapter),
            erlang:element(2, Drained);

        false ->
            Adapter
    end.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 226).
?DOC(" Apply one increment mutation and normalize frame drain across transport modes.\n").
-spec apply_increment(negotiated_state(), integer()) -> mutation_result().
apply_increment(State, Now_ms) ->
    Next_sequence = erlang:element(5, State) + 1,
    Adapter = prepare_adapter_for_mutation(
        erlang:element(2, State),
        erlang:element(5, State)
    ),
    Payload = lightspeed@protocol:encode(
        {event,
            <<"m56-inc-"/utf8,
                (erlang:integer_to_binary(Next_sequence))/binary>>,
            <<"increment"/utf8>>,
            <<"{}"/utf8>>}
    ),
    Received = lightspeed@transport@matrix:'receive'(
        Adapter,
        Payload,
        Now_ms,
        Next_sequence
    ),
    {Next_adapter, Frames} = drain_receive(Received),
    Counter = lightspeed@agent@session:counter(
        lightspeed@transport@matrix:session_state(Next_adapter)
    ),
    Mode = lightspeed@transport@matrix:mode_label(Next_adapter),
    Frame_labels = normalized_frame_labels(Frames),
    {mutation_result,
        {negotiated_state,
            Next_adapter,
            erlang:element(3, State),
            erlang:element(4, State),
            Next_sequence,
            erlang:element(6, State),
            erlang:element(7, State)},
        Frame_labels,
        Counter,
        Mode}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 363).
?DOC(" Protocol invariants signature.\n").
-spec protocol_invariant_signature(negotiated_state()) -> binary().
protocol_invariant_signature(State) ->
    <<<<<<<<<<<<<<"protocol="/utf8, (<<"lightspeed"/utf8>>)/binary>>/binary,
                            ":version="/utf8>>/binary,
                        (erlang:integer_to_binary(1))/binary>>/binary,
                    ":hello_current="/utf8>>/binary,
                (bool_label(
                    lightspeed@protocol:is_current_hello(
                        lightspeed@protocol:hello()
                    )
                ))/binary>>/binary,
            ":transport="/utf8>>/binary,
        (lightspeed@transport@matrix:active_transport_label(
            erlang:element(2, State)
        ))/binary>>.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 531).
-spec dispatches_label(list(lightspeed@form_compat:dispatch())) -> binary().
dispatches_label(Dispatches) ->
    join_with(
        <<","/utf8>>,
        gleam@list:map(Dispatches, fun lightspeed@form_compat:dispatch_label/1)
    ).

-file("src/lightspeed/transport/progressive_enhancement.gleam", 502).
-spec form_workflow_signature() -> binary().
form_workflow_signature() ->
    Runtime = lightspeed@form_compat:new(
        [{input_config, <<"title"/utf8>>, immediate},
            {input_config, <<"search"/utf8>>, {debounce, 30}}]
    ),
    {Runtime@1, Immediate} = lightspeed@form_compat:change(
        Runtime,
        <<"title"/utf8>>,
        <<"title=hello"/utf8>>,
        1
    ),
    {Runtime@2, Queued} = lightspeed@form_compat:change(
        Runtime@1,
        <<"search"/utf8>>,
        <<"search=lightspeed"/utf8>>,
        2
    ),
    {Runtime@3, Pending} = lightspeed@form_compat:tick(Runtime@2, 10),
    {Runtime@4, Flushed} = lightspeed@form_compat:tick(Runtime@3, 40),
    {_, Submitted} = lightspeed@form_compat:submit(
        Runtime@4,
        <<"title=hello"/utf8>>,
        41
    ),
    <<<<<<<<<<<<<<<<<<"immediate="/utf8,
                                        (lightspeed@form_compat:dispatch_label(
                                            Immediate
                                        ))/binary>>/binary,
                                    ":queued="/utf8>>/binary,
                                (lightspeed@form_compat:dispatch_label(Queued))/binary>>/binary,
                            ":pending="/utf8>>/binary,
                        (dispatches_label(Pending))/binary>>/binary,
                    ":flushed="/utf8>>/binary,
                (dispatches_label(Flushed))/binary>>/binary,
            ":submit="/utf8>>/binary,
        (lightspeed@form_compat:dispatch_label(Submitted))/binary>>.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 495).
-spec decode_navigation(
    lightspeed@event:inbound_event(),
    list(lightspeed@router:route_param())
) -> {ok, navigation_msg()} | {error, lightspeed@event:decode_error()}.
decode_navigation(_, _) ->
    {ok, navigation_noop}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 466).
-spec navigation_workflow_signature() -> binary().
navigation_workflow_signature() ->
    Table = begin
        _pipe = lightspeed@router:new(<<"not_found"/utf8>>),
        _pipe@1 = lightspeed@router:add(
            _pipe,
            <<"/todos/:id"/utf8>>,
            <<"todos_show"/utf8>>,
            fun decode_navigation/2
        ),
        lightspeed@router:add(
            _pipe@1,
            <<"/"/utf8>>,
            <<"todos_index"/utf8>>,
            fun decode_navigation/2
        )
    end,
    Patch_plan = lightspeed@navigation:plan(
        Table,
        <<"/todos/1"/utf8>>,
        <<"/todos/2"/utf8>>,
        <<"csrf-m56"/utf8>>
    ),
    Navigate_plan = lightspeed@navigation:plan(
        Table,
        <<"/"/utf8>>,
        <<"/todos/2"/utf8>>,
        <<"csrf-m56"/utf8>>
    ),
    Patch_steps = join_with(
        <<","/utf8>>,
        gleam@list:map(
            lightspeed@navigation:instructions(Patch_plan),
            fun lightspeed@agent@isa:describe/1
        )
    ),
    Navigate_steps = join_with(
        <<","/utf8>>,
        gleam@list:map(
            lightspeed@navigation:instructions(Navigate_plan),
            fun lightspeed@agent@isa:describe/1
        )
    ),
    <<<<<<<<<<<<<<<<<<<<<<"patch="/utf8,
                                                (lightspeed@navigation:mode_label(
                                                    lightspeed@navigation:mode(
                                                        Patch_plan
                                                    )
                                                ))/binary>>/binary,
                                            ":"/utf8>>/binary,
                                        (lightspeed@navigation:boundary_label(
                                            lightspeed@navigation:boundary(
                                                Patch_plan
                                            )
                                        ))/binary>>/binary,
                                    ":"/utf8>>/binary,
                                Patch_steps/binary>>/binary,
                            "|navigate="/utf8>>/binary,
                        (lightspeed@navigation:mode_label(
                            lightspeed@navigation:mode(Navigate_plan)
                        ))/binary>>/binary,
                    ":"/utf8>>/binary,
                (lightspeed@navigation:boundary_label(
                    lightspeed@navigation:boundary(Navigate_plan)
                ))/binary>>/binary,
            ":"/utf8>>/binary,
        Navigate_steps/binary>>.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 255).
?DOC(" Run deterministic navigation/form/mutation workflows without app branching.\n").
-spec run_degraded_workflows(negotiated_state(), integer()) -> {negotiated_state(),
    workflow_report()}.
run_degraded_workflows(State, Now_ms) ->
    Navigation_signature = navigation_workflow_signature(),
    Form_signature = form_workflow_signature(),
    Mutation = apply_increment(State, Now_ms),
    Mutation_signature = <<<<<<<<<<"mode="/utf8,
                        (erlang:element(5, Mutation))/binary>>/binary,
                    ":frames="/utf8>>/binary,
                (erlang:element(3, Mutation))/binary>>/binary,
            ":counter="/utf8>>/binary,
        (erlang:integer_to_binary(erlang:element(4, Mutation)))/binary>>,
    Mutation_equivalence_signature = <<<<<<"frames="/utf8,
                (erlang:element(3, Mutation))/binary>>/binary,
            ":counter="/utf8>>/binary,
        (erlang:integer_to_binary(erlang:element(4, Mutation)))/binary>>,
    Protocol_signature = protocol_invariant_signature(
        erlang:element(2, Mutation)
    ),
    {erlang:element(2, Mutation),
        {workflow_report,
            Navigation_signature,
            Form_signature,
            Mutation_signature,
            Mutation_equivalence_signature,
            Protocol_signature}}.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 289).
?DOC(" Stable transition signature.\n").
-spec transition_signature(negotiated_state()) -> binary().
transition_signature(State) ->
    join_with(<<","/utf8>>, lists:reverse(erlang:element(6, State))).

-file("src/lightspeed/transport/progressive_enhancement.gleam", 294).
?DOC(" Stable capability signature for current negotiated mode.\n").
-spec capability_signature(negotiated_state()) -> binary().
capability_signature(State) ->
    Ordered = lightspeed@transport@matrix:capability_enabled(
        erlang:element(2, State),
        ordered_client_events
    ),
    Reconnect = lightspeed@transport@matrix:capability_enabled(
        erlang:element(2, State),
        reconnect_semantics
    ),
    Push = lightspeed@transport@matrix:capability_enabled(
        erlang:element(2, State),
        server_push_frames
    ),
    Bidirectional = lightspeed@transport@matrix:capability_enabled(
        erlang:element(2, State),
        bidirectional_channel
    ),
    Fallback = lightspeed@transport@matrix:capability_enabled(
        erlang:element(2, State),
        progressive_fallback
    ),
    <<<<<<<<<<<<<<<<<<"ordered="/utf8, (bool_label(Ordered))/binary>>/binary,
                                    ":reconnect="/utf8>>/binary,
                                (bool_label(Reconnect))/binary>>/binary,
                            ":server_push="/utf8>>/binary,
                        (bool_label(Push))/binary>>/binary,
                    ":bidirectional="/utf8>>/binary,
                (bool_label(Bidirectional))/binary>>/binary,
            ":progressive_fallback="/utf8>>/binary,
        (bool_label(Fallback))/binary>>.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 326).
?DOC(" Proxy assessment accessor for an established state.\n").
-spec proxy_assessment(negotiated_state()) -> proxy_assessment().
proxy_assessment(State) ->
    erlang:element(7, State).

-file("src/lightspeed/transport/progressive_enhancement.gleam", 331).
?DOC(" Current mode label accessor.\n").
-spec mode_label(negotiated_state()) -> binary().
mode_label(State) ->
    lightspeed@transport@matrix:mode_label(erlang:element(2, State)).

-file("src/lightspeed/transport/progressive_enhancement.gleam", 336).
?DOC(" Current transport label accessor.\n").
-spec transport_label(negotiated_state()) -> binary().
transport_label(State) ->
    lightspeed@transport@matrix:active_transport_label(erlang:element(2, State)).

-file("src/lightspeed/transport/progressive_enhancement.gleam", 341).
?DOC(" Workflow signature accessor.\n").
-spec workflow_signature(workflow_report()) -> binary().
workflow_signature(Report) ->
    <<<<<<<<<<<<<<"navigation="/utf8, (erlang:element(2, Report))/binary>>/binary,
                            "|form="/utf8>>/binary,
                        (erlang:element(3, Report))/binary>>/binary,
                    "|mutation="/utf8>>/binary,
                (erlang:element(4, Report))/binary>>/binary,
            "|protocol="/utf8>>/binary,
        (erlang:element(6, Report))/binary>>.

-file("src/lightspeed/transport/progressive_enhancement.gleam", 353).
?DOC(" Cross-mode workflow equivalence signature.\n").
-spec workflow_equivalence_signature(workflow_report()) -> binary().
workflow_equivalence_signature(Report) ->
    <<<<<<<<<<"navigation="/utf8, (erlang:element(2, Report))/binary>>/binary,
                    "|form="/utf8>>/binary,
                (erlang:element(3, Report))/binary>>/binary,
            "|mutation="/utf8>>/binary,
        (erlang:element(5, Report))/binary>>.