src/lightspeed@release@production_readiness.erl

-module(lightspeed@release@production_readiness).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/lightspeed/release/production_readiness.gleam").
-export([required_gates/0, failing_required_gates/0, ready/0, gate_name/1, risk_class/1, gate_passed/1, gate_required/1, remediation/1, risk_class_label/1, gate_signature/1, snapshot_signature/0]).
-export_type([risk_class/0, gate_status/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(" Production-readiness gate bundle contracts for post-M60 certification.\n").

-type risk_class() :: runtime_resilience |
    data_integrity |
    tenant_isolation |
    operational_control |
    release_governance.

-type gate_status() :: {gate_status,
        binary(),
        risk_class(),
        boolean(),
        binary(),
        binary(),
        binary(),
        boolean()}.

-file("src/lightspeed/release/production_readiness.gleam", 218).
-spec gate(binary(), risk_class(), boolean(), binary(), binary(), binary()) -> gate_status().
gate(
    Name,
    Risk_class,
    Required,
    Expected_prefix,
    Observed_signature,
    Remediation
) ->
    Passed = gleam_stdlib:string_starts_with(
        Observed_signature,
        Expected_prefix
    ),
    {gate_status,
        Name,
        Risk_class,
        Required,
        Expected_prefix,
        Observed_signature,
        Remediation,
        Passed}.

-file("src/lightspeed/release/production_readiness.gleam", 43).
?DOC(" Required production-readiness gates.\n").
-spec required_gates() -> list(gate_status()).
required_gates() ->
    [gate(
            <<"m27_failover_fixture"/utf8>>,
            runtime_resilience,
            true,
            <<"m27.snapshot.v1|"/utf8>>,
            lightspeed@ops@failover_harness:snapshot_signature(),
            <<"make failover-fixture-gate"/utf8>>
        ),
        gate(
            <<"m33_etl_reliability_fixture"/utf8>>,
            data_integrity,
            true,
            <<"m33.snapshot.v1|"/utf8>>,
            lightspeed@ops@etl_reliability_harness:snapshot_signature(),
            <<"make etl-fixture-gate"/utf8>>
        ),
        gate(
            <<"m40_operations_kit_fixture"/utf8>>,
            operational_control,
            true,
            <<"m40.snapshot.v1|"/utf8>>,
            lightspeed@ops@operations_kit_harness:snapshot_signature(),
            <<"make operations-kit-fixture-gate"/utf8>>
        ),
        gate(
            <<"m42_replay_diagnostics_fixture"/utf8>>,
            operational_control,
            true,
            <<"m42.snapshot.v1|"/utf8>>,
            lightspeed@ops@replay_diagnostics_harness:snapshot_signature(),
            <<"make replay-diagnostics-fixture-gate"/utf8>>
        ),
        gate(
            <<"m47_maturity_fixture"/utf8>>,
            release_governance,
            true,
            <<"m47.snapshot.v1|"/utf8>>,
            lightspeed@ops@maturity_harness:snapshot_signature(),
            <<"make maturity-fixture-gate"/utf8>>
        ),
        gate(
            <<"m49_durable_backend_fixture"/utf8>>,
            runtime_resilience,
            true,
            <<"m49.snapshot.v1|"/utf8>>,
            lightspeed@ops@durable_backend_harness:snapshot_signature(),
            <<"make durable-backend-fixture-gate"/utf8>>
        ),
        gate(
            <<"m50_overload_fixture"/utf8>>,
            runtime_resilience,
            true,
            <<"m50.snapshot.v1|"/utf8>>,
            lightspeed@ops@overload_harness:snapshot_signature(),
            <<"make overload-fixture-gate"/utf8>>
        ),
        gate(
            <<"m52_tenant_expansion_fixture"/utf8>>,
            tenant_isolation,
            true,
            <<"m52.snapshot.v1|"/utf8>>,
            lightspeed@ops@tenant_expansion_harness:snapshot_signature(),
            <<"make tenant-expansion-fixture-gate"/utf8>>
        ),
        gate(
            <<"m53_chaos_expansion_fixture"/utf8>>,
            runtime_resilience,
            true,
            <<"m53.snapshot.v1|"/utf8>>,
            lightspeed@ops@chaos_expansion_harness:snapshot_signature(),
            <<"make chaos-expansion-fixture-gate"/utf8>>
        ),
        gate(
            <<"m54_operational_autopilot_fixture"/utf8>>,
            operational_control,
            true,
            <<"m54.snapshot.v1|"/utf8>>,
            lightspeed@ops@operational_autopilot_harness:snapshot_signature(),
            <<"make operational-autopilot-fixture-gate"/utf8>>
        ),
        gate(
            <<"m60_pipeline_operations_surface_fixture"/utf8>>,
            data_integrity,
            true,
            <<"m60.snapshot.v1|"/utf8>>,
            lightspeed@ops@pipeline_operations_surface_harness:snapshot_signature(
                
            ),
            <<"make pipeline-operations-surface-fixture-gate"/utf8>>
        )].

-file("src/lightspeed/release/production_readiness.gleam", 239).
-spec collect_failing_required(list(gate_status()), list(gate_status())) -> list(gate_status()).
collect_failing_required(Gates, Failing_rev) ->
    case Gates of
        [] ->
            Failing_rev;

        [Entry | Rest] ->
            case erlang:element(4, Entry) andalso not erlang:element(8, Entry) of
                true ->
                    collect_failing_required(Rest, [Entry | Failing_rev]);

                false ->
                    collect_failing_required(Rest, Failing_rev)
            end
    end.

-file("src/lightspeed/release/production_readiness.gleam", 145).
?DOC(" Required gates that are currently failing.\n").
-spec failing_required_gates() -> list(gate_status()).
failing_required_gates() ->
    _pipe = collect_failing_required(required_gates(), []),
    lists:reverse(_pipe).

-file("src/lightspeed/release/production_readiness.gleam", 137).
?DOC(" `True` when all required gates pass.\n").
-spec ready() -> boolean().
ready() ->
    case failing_required_gates() of
        [] ->
            true;

        _ ->
            false
    end.

-file("src/lightspeed/release/production_readiness.gleam", 151).
?DOC(" Gate name accessor.\n").
-spec gate_name(gate_status()) -> binary().
gate_name(Gate) ->
    erlang:element(2, Gate).

-file("src/lightspeed/release/production_readiness.gleam", 156).
?DOC(" Risk-class accessor.\n").
-spec risk_class(gate_status()) -> risk_class().
risk_class(Gate) ->
    erlang:element(3, Gate).

-file("src/lightspeed/release/production_readiness.gleam", 161).
?DOC(" Passed accessor.\n").
-spec gate_passed(gate_status()) -> boolean().
gate_passed(Gate) ->
    erlang:element(8, Gate).

-file("src/lightspeed/release/production_readiness.gleam", 166).
?DOC(" Required accessor.\n").
-spec gate_required(gate_status()) -> boolean().
gate_required(Gate) ->
    erlang:element(4, Gate).

-file("src/lightspeed/release/production_readiness.gleam", 171).
?DOC(" Remediation accessor.\n").
-spec remediation(gate_status()) -> binary().
remediation(Gate) ->
    erlang:element(7, Gate).

-file("src/lightspeed/release/production_readiness.gleam", 176).
?DOC(" Stable risk-class label.\n").
-spec risk_class_label(risk_class()) -> binary().
risk_class_label(Risk_class) ->
    case Risk_class of
        runtime_resilience ->
            <<"runtime_resilience"/utf8>>;

        data_integrity ->
            <<"data_integrity"/utf8>>;

        tenant_isolation ->
            <<"tenant_isolation"/utf8>>;

        operational_control ->
            <<"operational_control"/utf8>>;

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

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

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

-file("src/lightspeed/release/production_readiness.gleam", 187).
?DOC(" Stable gate signature.\n").
-spec gate_signature(gate_status()) -> binary().
gate_signature(Gate) ->
    <<<<<<<<<<<<<<<<<<<<<<<<<<"name="/utf8, (erlang:element(2, Gate))/binary>>/binary,
                                                    "|risk="/utf8>>/binary,
                                                (risk_class_label(
                                                    erlang:element(3, Gate)
                                                ))/binary>>/binary,
                                            "|required="/utf8>>/binary,
                                        (bool_label(erlang:element(4, Gate)))/binary>>/binary,
                                    "|expected="/utf8>>/binary,
                                (erlang:element(5, Gate))/binary>>/binary,
                            "|observed="/utf8>>/binary,
                        (erlang:element(6, Gate))/binary>>/binary,
                    "|passed="/utf8>>/binary,
                (bool_label(erlang:element(8, Gate)))/binary>>/binary,
            "|remediation="/utf8>>/binary,
        (erlang:element(7, Gate))/binary>>.

-file("src/lightspeed/release/production_readiness.gleam", 260).
-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/release/production_readiness.gleam", 205).
?DOC(" Deterministic production-readiness snapshot signature.\n").
-spec snapshot_signature() -> binary().
snapshot_signature() ->
    Gates = required_gates(),
    <<<<<<<<<<<<<<"prod.ready.v"/utf8, (erlang:integer_to_binary(1))/binary>>/binary,
                            "|ready="/utf8>>/binary,
                        (bool_label(ready()))/binary>>/binary,
                    "|gate_count="/utf8>>/binary,
                (erlang:integer_to_binary(erlang:length(Gates)))/binary>>/binary,
            "|gates="/utf8>>/binary,
        (join_with(<<";"/utf8>>, gleam@list:map(Gates, fun gate_signature/1)))/binary>>.