src/lightspeed@platform@foundation.erl

-module(lightspeed@platform@foundation).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/lightspeed/platform/foundation.gleam").
-export([required_workflows/0, b2b_saas_profile/0, marketplace_profile/0, operations_platform_profile/0, reference_profiles/0, explicit_override_points/1, valid/1, requires_framework_internal_patching/1, supports_workflow/2, workflow_runs_without_internal_patching/2, name/1, surfaces/1, workflows/1, workflow_label/1, surface_label/1, metering_source_label/1, override_point_label/1, billing_provider_label/1, policy_provider_label/1, admin_provider_label/1, auth_provider_label/1, signature/1, seam_contract_signature/1, workflow_matrix_signature/1]).
-export_type([override_point/0, auth_provider/0, admin_provider/0, policy_provider/0, billing_provider/0, metering_source/0, auth_seam/0, admin_seam/0, policy_seam/0, billing_seam/0, product_surface/0, lifecycle_workflow/0, app_profile/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(" App-platform foundation contracts and composition profiles for M38.\n").

-type override_point() :: {hook, binary(), binary()} |
    {adapter, binary()} |
    {route_namespace, binary(), binary()}.

-type auth_provider() :: {first_party, binary()} |
    {oidc, binary()} |
    {hybrid, binary(), binary()}.

-type admin_provider() :: {embedded_panel, binary()} |
    {external_backoffice, binary()} |
    {mixed_admin, binary(), binary()}.

-type policy_provider() :: {role_based, binary()} |
    {attribute_based, binary()} |
    {mixed_policy, binary(), binary()}.

-type billing_provider() :: {stripe, binary()} |
    {paddle, binary()} |
    {mixed_billing, binary(), binary()}.

-type metering_source() :: {event_log, binary()} |
    {usage_pipeline, binary()} |
    {hybrid_metering, binary(), binary()}.

-type auth_seam() :: {auth_seam,
        auth_provider(),
        override_point(),
        integer(),
        boolean(),
        boolean()}.

-type admin_seam() :: {admin_seam,
        admin_provider(),
        override_point(),
        binary(),
        binary(),
        boolean()}.

-type policy_seam() :: {policy_seam,
        policy_provider(),
        override_point(),
        boolean(),
        boolean(),
        boolean()}.

-type billing_seam() :: {billing_seam,
        billing_provider(),
        override_point(),
        metering_source(),
        boolean(),
        boolean()}.

-type product_surface() :: customer_portal |
    admin_console |
    public_api |
    partner_api |
    operations_console.

-type lifecycle_workflow() :: account_signup_activation |
    subscription_upgrade |
    admin_approval_escalation |
    tenant_policy_review.

-type app_profile() :: {app_profile,
        binary(),
        auth_seam(),
        admin_seam(),
        policy_seam(),
        billing_seam(),
        list(product_surface()),
        list(lifecycle_workflow()),
        boolean()}.

-file("src/lightspeed/platform/foundation.gleam", 287).
?DOC(" Required core workflows for M38 conformance.\n").
-spec required_workflows() -> list(lifecycle_workflow()).
required_workflows() ->
    [account_signup_activation,
        subscription_upgrade,
        admin_approval_escalation,
        tenant_policy_review].

-file("src/lightspeed/platform/foundation.gleam", 125).
?DOC(" B2B SaaS profile.\n").
-spec b2b_saas_profile() -> app_profile().
b2b_saas_profile() ->
    {app_profile,
        <<"b2b_saas"/utf8>>,
        {auth_seam,
            {hybrid, <<"MyApp.Auth.Password"/utf8>>, <<"MyApp.Auth.Oidc"/utf8>>},
            {hook,
                <<"MyApp.AuthHooks"/utf8>>,
                <<"resolve_session_context"/utf8>>},
            480,
            true,
            true},
        {admin_seam,
            {embedded_panel, <<"MyApp.Admin.Panel"/utf8>>},
            {route_namespace, <<"MyApp.AdminRouter"/utf8>>, <<"/admin"/utf8>>},
            <<"MyApp.AdminAudit"/utf8>>,
            <<"platform_admin"/utf8>>,
            true},
        {policy_seam,
            {mixed_policy,
                <<"MyApp.Policy.Rbac"/utf8>>,
                <<"MyApp.Policy.Abac"/utf8>>},
            {adapter, <<"MyApp.PolicyAdapter"/utf8>>},
            true,
            true,
            true},
        {billing_seam,
            {stripe, <<"MyApp.Billing.Stripe"/utf8>>},
            {hook,
                <<"MyApp.BillingHooks"/utf8>>,
                <<"transform_invoice_event"/utf8>>},
            {usage_pipeline, <<"MyApp.BillingUsagePipeline"/utf8>>},
            true,
            true},
        [customer_portal, admin_console, public_api, operations_console],
        required_workflows(),
        false}.

-file("src/lightspeed/platform/foundation.gleam", 177).
?DOC(" Marketplace profile with partner surface.\n").
-spec marketplace_profile() -> app_profile().
marketplace_profile() ->
    {app_profile,
        <<"marketplace"/utf8>>,
        {auth_seam,
            {oidc, <<"MyApp.Auth.Oidc"/utf8>>},
            {adapter, <<"MyApp.AuthProviderAdapter"/utf8>>},
            240,
            true,
            false},
        {admin_seam,
            {mixed_admin,
                <<"MyApp.Admin.Panel"/utf8>>,
                <<"MyApp.Admin.Backoffice"/utf8>>},
            {hook,
                <<"MyApp.AdminHooks"/utf8>>,
                <<"authorize_bulk_action"/utf8>>},
            <<"MyApp.AdminAudit"/utf8>>,
            <<"marketplace_admin"/utf8>>,
            true},
        {policy_seam,
            {attribute_based, <<"MyApp.Policy.Abac"/utf8>>},
            {route_namespace, <<"MyApp.PolicyRoutes"/utf8>>, <<"/policy"/utf8>>},
            true,
            true,
            true},
        {billing_seam,
            {mixed_billing,
                <<"MyApp.Billing.Stripe"/utf8>>,
                <<"MyApp.Billing.Paddle"/utf8>>},
            {adapter, <<"MyApp.BillingAdapter"/utf8>>},
            {hybrid_metering,
                <<"MyApp.BillingUsagePipeline"/utf8>>,
                <<"MyApp.BillingReplay"/utf8>>},
            true,
            true},
        [customer_portal,
            admin_console,
            public_api,
            partner_api,
            operations_console],
        required_workflows(),
        false}.

-file("src/lightspeed/platform/foundation.gleam", 233).
?DOC(" Operations-heavy product profile.\n").
-spec operations_platform_profile() -> app_profile().
operations_platform_profile() ->
    {app_profile,
        <<"operations_platform"/utf8>>,
        {auth_seam,
            {first_party, <<"MyApp.Auth.Password"/utf8>>},
            {route_namespace, <<"MyApp.AuthRoutes"/utf8>>, <<"/auth"/utf8>>},
            720,
            true,
            true},
        {admin_seam,
            {external_backoffice, <<"MyApp.Admin.Backoffice"/utf8>>},
            {adapter, <<"MyApp.AdminAdapter"/utf8>>},
            <<"MyApp.AdminAudit"/utf8>>,
            <<"ops_super_admin"/utf8>>,
            true},
        {policy_seam,
            {role_based, <<"MyApp.Policy.Rbac"/utf8>>},
            {hook,
                <<"MyApp.PolicyHooks"/utf8>>,
                <<"annotate_denial_reason"/utf8>>},
            true,
            true,
            true},
        {billing_seam,
            {paddle, <<"MyApp.Billing.Paddle"/utf8>>},
            {route_namespace,
                <<"MyApp.BillingRoutes"/utf8>>,
                <<"/billing"/utf8>>},
            {event_log, <<"MyApp.BillingEventLog"/utf8>>},
            true,
            true},
        [customer_portal, admin_console, public_api, operations_console],
        required_workflows(),
        false}.

-file("src/lightspeed/platform/foundation.gleam", 282).
?DOC(" Reference M38 product profiles.\n").
-spec reference_profiles() -> list(app_profile()).
reference_profiles() ->
    [b2b_saas_profile(), marketplace_profile(), operations_platform_profile()].

-file("src/lightspeed/platform/foundation.gleam", 646).
-spec module_external(binary()) -> boolean().
module_external(Module_name) ->
    ((Module_name /= <<""/utf8>>) andalso not gleam_stdlib:contains_string(
        Module_name,
        <<"lightspeed/framework"/utf8>>
    ))
    andalso not gleam_stdlib:contains_string(
        Module_name,
        <<"lightspeed/component"/utf8>>
    ).

-file("src/lightspeed/platform/foundation.gleam", 572).
-spec override_point_valid(override_point()) -> boolean().
override_point_valid(Value) ->
    case Value of
        {hook, Module, Hook} ->
            module_external(Module) andalso (Hook /= <<""/utf8>>);

        {adapter, Module@1} ->
            module_external(Module@1);

        {route_namespace, Module@2, Namespace} ->
            module_external(Module@2) andalso (Namespace /= <<""/utf8>>)
    end.

-file("src/lightspeed/platform/foundation.gleam", 314).
?DOC(" All seams have explicit and external override points.\n").
-spec explicit_override_points(app_profile()) -> boolean().
explicit_override_points(Profile) ->
    ((override_point_valid(erlang:element(3, erlang:element(3, Profile)))
    andalso override_point_valid(erlang:element(3, erlang:element(4, Profile))))
    andalso override_point_valid(erlang:element(3, erlang:element(5, Profile))))
    andalso override_point_valid(erlang:element(3, erlang:element(6, Profile))).

-file("src/lightspeed/platform/foundation.gleam", 666).
-spec has_workflow(list(lifecycle_workflow()), lifecycle_workflow()) -> boolean().
has_workflow(Workflows, Expected) ->
    case Workflows of
        [] ->
            false;

        [Workflow | Rest] ->
            case Workflow =:= Expected of
                true ->
                    true;

                false ->
                    has_workflow(Rest, Expected)
            end
    end.

-file("src/lightspeed/platform/foundation.gleam", 652).
-spec has_surface(list(product_surface()), product_surface()) -> boolean().
has_surface(Surfaces, Expected) ->
    case Surfaces of
        [] ->
            false;

        [Surface | Rest] ->
            case Surface =:= Expected of
                true ->
                    true;

                false ->
                    has_surface(Rest, Expected)
            end
    end.

-file("src/lightspeed/platform/foundation.gleam", 617).
-spec metering_source_valid(metering_source()) -> boolean().
metering_source_valid(Source) ->
    case Source of
        {event_log, Module} ->
            module_external(Module);

        {usage_pipeline, Module@1} ->
            module_external(Module@1);

        {hybrid_metering, Primary, Fallback} ->
            module_external(Primary) andalso module_external(Fallback)
    end.

-file("src/lightspeed/platform/foundation.gleam", 608).
-spec billing_provider_valid(billing_provider()) -> boolean().
billing_provider_valid(Provider) ->
    case Provider of
        {stripe, Module} ->
            module_external(Module);

        {paddle, Module@1} ->
            module_external(Module@1);

        {mixed_billing, Primary, Fallback} ->
            module_external(Primary) andalso module_external(Fallback)
    end.

-file("src/lightspeed/platform/foundation.gleam", 516).
-spec valid_billing_seam(billing_seam()) -> boolean().
valid_billing_seam(Seam) ->
    (((billing_provider_valid(erlang:element(2, Seam)) andalso override_point_valid(
        erlang:element(3, Seam)
    ))
    andalso metering_source_valid(erlang:element(4, Seam)))
    andalso erlang:element(5, Seam))
    andalso erlang:element(6, Seam).

-file("src/lightspeed/platform/foundation.gleam", 599).
-spec policy_provider_valid(policy_provider()) -> boolean().
policy_provider_valid(Provider) ->
    case Provider of
        {role_based, Module} ->
            module_external(Module);

        {attribute_based, Module@1} ->
            module_external(Module@1);

        {mixed_policy, Primary, Fallback} ->
            module_external(Primary) andalso module_external(Fallback)
    end.

-file("src/lightspeed/platform/foundation.gleam", 508).
-spec valid_policy_seam(policy_seam()) -> boolean().
valid_policy_seam(Seam) ->
    (((policy_provider_valid(erlang:element(2, Seam)) andalso override_point_valid(
        erlang:element(3, Seam)
    ))
    andalso erlang:element(4, Seam))
    andalso erlang:element(5, Seam))
    andalso erlang:element(6, Seam).

-file("src/lightspeed/platform/foundation.gleam", 590).
-spec admin_provider_valid(admin_provider()) -> boolean().
admin_provider_valid(Provider) ->
    case Provider of
        {embedded_panel, Module} ->
            module_external(Module);

        {external_backoffice, Module@1} ->
            module_external(Module@1);

        {mixed_admin, Primary, Fallback} ->
            module_external(Primary) andalso module_external(Fallback)
    end.

-file("src/lightspeed/platform/foundation.gleam", 500).
-spec valid_admin_seam(admin_seam()) -> boolean().
valid_admin_seam(Seam) ->
    (((admin_provider_valid(erlang:element(2, Seam)) andalso override_point_valid(
        erlang:element(3, Seam)
    ))
    andalso (erlang:element(4, Seam) /= <<""/utf8>>))
    andalso (erlang:element(5, Seam) /= <<""/utf8>>))
    andalso erlang:element(6, Seam).

-file("src/lightspeed/platform/foundation.gleam", 581).
-spec auth_provider_valid(auth_provider()) -> boolean().
auth_provider_valid(Provider) ->
    case Provider of
        {first_party, Module} ->
            module_external(Module);

        {oidc, Module@1} ->
            module_external(Module@1);

        {hybrid, Primary, Fallback} ->
            module_external(Primary) andalso module_external(Fallback)
    end.

-file("src/lightspeed/platform/foundation.gleam", 493).
-spec valid_auth_seam(auth_seam()) -> boolean().
valid_auth_seam(Seam) ->
    ((auth_provider_valid(erlang:element(2, Seam)) andalso override_point_valid(
        erlang:element(3, Seam)
    ))
    andalso (erlang:element(4, Seam) > 0))
    andalso erlang:element(5, Seam).

-file("src/lightspeed/platform/foundation.gleam", 297).
?DOC(" Validate one app-platform profile.\n").
-spec valid(app_profile()) -> boolean().
valid(Profile) ->
    ((((((((((((erlang:element(2, Profile) /= <<""/utf8>>) andalso valid_auth_seam(
        erlang:element(3, Profile)
    ))
    andalso valid_admin_seam(erlang:element(4, Profile)))
    andalso valid_policy_seam(erlang:element(5, Profile)))
    andalso valid_billing_seam(erlang:element(6, Profile)))
    andalso has_surface(erlang:element(7, Profile), customer_portal))
    andalso has_surface(erlang:element(7, Profile), admin_console))
    andalso has_surface(erlang:element(7, Profile), public_api))
    andalso has_workflow(erlang:element(8, Profile), account_signup_activation))
    andalso has_workflow(erlang:element(8, Profile), subscription_upgrade))
    andalso has_workflow(erlang:element(8, Profile), admin_approval_escalation))
    andalso has_workflow(erlang:element(8, Profile), tenant_policy_review))
    andalso explicit_override_points(Profile).

-file("src/lightspeed/platform/foundation.gleam", 322).
?DOC(" Whether profile requires framework-internal patching.\n").
-spec requires_framework_internal_patching(app_profile()) -> boolean().
requires_framework_internal_patching(Profile) ->
    erlang:element(9, Profile).

-file("src/lightspeed/platform/foundation.gleam", 327).
?DOC(" Check whether one workflow is supported by one profile.\n").
-spec supports_workflow(app_profile(), lifecycle_workflow()) -> boolean().
supports_workflow(Profile, Workflow) ->
    has_workflow(erlang:element(8, Profile), Workflow).

-file("src/lightspeed/platform/foundation.gleam", 642).
-spec metering_source_external(metering_source()) -> boolean().
metering_source_external(Source) ->
    metering_source_valid(Source).

-file("src/lightspeed/platform/foundation.gleam", 638).
-spec billing_provider_external(billing_provider()) -> boolean().
billing_provider_external(Provider) ->
    billing_provider_valid(Provider).

-file("src/lightspeed/platform/foundation.gleam", 634).
-spec policy_provider_external(policy_provider()) -> boolean().
policy_provider_external(Provider) ->
    policy_provider_valid(Provider).

-file("src/lightspeed/platform/foundation.gleam", 630).
-spec admin_provider_external(admin_provider()) -> boolean().
admin_provider_external(Provider) ->
    admin_provider_valid(Provider).

-file("src/lightspeed/platform/foundation.gleam", 626).
-spec auth_provider_external(auth_provider()) -> boolean().
auth_provider_external(Provider) ->
    auth_provider_valid(Provider).

-file("src/lightspeed/platform/foundation.gleam", 484).
-spec seams_external(app_profile()) -> boolean().
seams_external(Profile) ->
    ((((auth_provider_external(erlang:element(2, erlang:element(3, Profile)))
    andalso admin_provider_external(
        erlang:element(2, erlang:element(4, Profile))
    ))
    andalso policy_provider_external(
        erlang:element(2, erlang:element(5, Profile))
    ))
    andalso billing_provider_external(
        erlang:element(2, erlang:element(6, Profile))
    ))
    andalso metering_source_external(
        erlang:element(4, erlang:element(6, Profile))
    ))
    andalso module_external(erlang:element(4, erlang:element(4, Profile))).

-file("src/lightspeed/platform/foundation.gleam", 335).
?DOC(" Verify one workflow can run through explicit seams without framework patching.\n").
-spec workflow_runs_without_internal_patching(
    app_profile(),
    lifecycle_workflow()
) -> boolean().
workflow_runs_without_internal_patching(Profile, Workflow) ->
    ((supports_workflow(Profile, Workflow) andalso not erlang:element(
        9,
        Profile
    ))
    andalso explicit_override_points(Profile))
    andalso seams_external(Profile).

-file("src/lightspeed/platform/foundation.gleam", 346).
?DOC(" Profile name accessor.\n").
-spec name(app_profile()) -> binary().
name(Profile) ->
    erlang:element(2, Profile).

-file("src/lightspeed/platform/foundation.gleam", 351).
?DOC(" Profile surfaces accessor.\n").
-spec surfaces(app_profile()) -> list(product_surface()).
surfaces(Profile) ->
    erlang:element(7, Profile).

-file("src/lightspeed/platform/foundation.gleam", 356).
?DOC(" Profile workflows accessor.\n").
-spec workflows(app_profile()) -> list(lifecycle_workflow()).
workflows(Profile) ->
    erlang:element(8, Profile).

-file("src/lightspeed/platform/foundation.gleam", 680).
-spec bool_label(boolean()) -> binary().
bool_label(Value) ->
    case Value of
        true ->
            <<"true"/utf8>>;

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

-file("src/lightspeed/platform/foundation.gleam", 475).
?DOC(" Workflow label.\n").
-spec workflow_label(lifecycle_workflow()) -> binary().
workflow_label(Workflow) ->
    case Workflow of
        account_signup_activation ->
            <<"account_signup_activation"/utf8>>;

        subscription_upgrade ->
            <<"subscription_upgrade"/utf8>>;

        admin_approval_escalation ->
            <<"admin_approval_escalation"/utf8>>;

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

-file("src/lightspeed/platform/foundation.gleam", 687).
-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/platform/foundation.gleam", 464).
?DOC(" Product-surface label.\n").
-spec surface_label(product_surface()) -> binary().
surface_label(Surface) ->
    case Surface of
        customer_portal ->
            <<"customer_portal"/utf8>>;

        admin_console ->
            <<"admin_console"/utf8>>;

        public_api ->
            <<"public_api"/utf8>>;

        partner_api ->
            <<"partner_api"/utf8>>;

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

-file("src/lightspeed/platform/foundation.gleam", 454).
?DOC(" Metering-source label.\n").
-spec metering_source_label(metering_source()) -> binary().
metering_source_label(Source) ->
    case Source of
        {event_log, Module} ->
            <<"event_log:"/utf8, Module/binary>>;

        {usage_pipeline, Module@1} ->
            <<"usage_pipeline:"/utf8, Module@1/binary>>;

        {hybrid_metering, Primary, Fallback} ->
            <<<<<<"hybrid_metering:"/utf8, Primary/binary>>/binary, ":"/utf8>>/binary,
                Fallback/binary>>
    end.

-file("src/lightspeed/platform/foundation.gleam", 405).
?DOC(" Override-point label.\n").
-spec override_point_label(override_point()) -> binary().
override_point_label(Value) ->
    case Value of
        {hook, Module, Hook} ->
            <<<<<<"hook:"/utf8, Module/binary>>/binary, ":"/utf8>>/binary,
                Hook/binary>>;

        {adapter, Module@1} ->
            <<"adapter:"/utf8, Module@1/binary>>;

        {route_namespace, Module@2, Namespace} ->
            <<<<<<"route_namespace:"/utf8, Module@2/binary>>/binary, ":"/utf8>>/binary,
                Namespace/binary>>
    end.

-file("src/lightspeed/platform/foundation.gleam", 444).
?DOC(" Billing-provider label.\n").
-spec billing_provider_label(billing_provider()) -> binary().
billing_provider_label(Provider) ->
    case Provider of
        {stripe, Module} ->
            <<"stripe:"/utf8, Module/binary>>;

        {paddle, Module@1} ->
            <<"paddle:"/utf8, Module@1/binary>>;

        {mixed_billing, Primary, Fallback} ->
            <<<<<<"mixed_billing:"/utf8, Primary/binary>>/binary, ":"/utf8>>/binary,
                Fallback/binary>>
    end.

-file("src/lightspeed/platform/foundation.gleam", 560).
-spec billing_seam_signature(billing_seam()) -> binary().
billing_seam_signature(Seam) ->
    <<<<<<<<<<<<<<<<(billing_provider_label(erlang:element(2, Seam)))/binary,
                                    "|override="/utf8>>/binary,
                                (override_point_label(erlang:element(3, Seam)))/binary>>/binary,
                            "|metering="/utf8>>/binary,
                        (metering_source_label(erlang:element(4, Seam)))/binary>>/binary,
                    "|webhook_verification="/utf8>>/binary,
                (bool_label(erlang:element(5, Seam)))/binary>>/binary,
            "|dunning="/utf8>>/binary,
        (bool_label(erlang:element(6, Seam)))/binary>>.

-file("src/lightspeed/platform/foundation.gleam", 434).
?DOC(" Policy-provider label.\n").
-spec policy_provider_label(policy_provider()) -> binary().
policy_provider_label(Provider) ->
    case Provider of
        {role_based, Module} ->
            <<"rbac:"/utf8, Module/binary>>;

        {attribute_based, Module@1} ->
            <<"abac:"/utf8, Module@1/binary>>;

        {mixed_policy, Primary, Fallback} ->
            <<<<<<"mixed_policy:"/utf8, Primary/binary>>/binary, ":"/utf8>>/binary,
                Fallback/binary>>
    end.

-file("src/lightspeed/platform/foundation.gleam", 548).
-spec policy_seam_signature(policy_seam()) -> binary().
policy_seam_signature(Seam) ->
    <<<<<<<<<<<<<<<<(policy_provider_label(erlang:element(2, Seam)))/binary,
                                    "|override="/utf8>>/binary,
                                (override_point_label(erlang:element(3, Seam)))/binary>>/binary,
                            "|tenant_scoped="/utf8>>/binary,
                        (bool_label(erlang:element(4, Seam)))/binary>>/binary,
                    "|deny_by_default="/utf8>>/binary,
                (bool_label(erlang:element(5, Seam)))/binary>>/binary,
            "|decision_trace="/utf8>>/binary,
        (bool_label(erlang:element(6, Seam)))/binary>>.

-file("src/lightspeed/platform/foundation.gleam", 424).
?DOC(" Admin-provider label.\n").
-spec admin_provider_label(admin_provider()) -> binary().
admin_provider_label(Provider) ->
    case Provider of
        {embedded_panel, Module} ->
            <<"embedded_panel:"/utf8, Module/binary>>;

        {external_backoffice, Module@1} ->
            <<"external_backoffice:"/utf8, Module@1/binary>>;

        {mixed_admin, Primary, Fallback} ->
            <<<<<<"mixed_admin:"/utf8, Primary/binary>>/binary, ":"/utf8>>/binary,
                Fallback/binary>>
    end.

-file("src/lightspeed/platform/foundation.gleam", 536).
-spec admin_seam_signature(admin_seam()) -> binary().
admin_seam_signature(Seam) ->
    <<<<<<<<<<<<<<<<(admin_provider_label(erlang:element(2, Seam)))/binary,
                                    "|override="/utf8>>/binary,
                                (override_point_label(erlang:element(3, Seam)))/binary>>/binary,
                            "|audit_sink="/utf8>>/binary,
                        (erlang:element(4, Seam))/binary>>/binary,
                    "|break_glass_role="/utf8>>/binary,
                (erlang:element(5, Seam))/binary>>/binary,
            "|approval_workflow="/utf8>>/binary,
        (bool_label(erlang:element(6, Seam)))/binary>>.

-file("src/lightspeed/platform/foundation.gleam", 415).
?DOC(" Auth-provider label.\n").
-spec auth_provider_label(auth_provider()) -> binary().
auth_provider_label(Provider) ->
    case Provider of
        {first_party, Module} ->
            <<"first_party:"/utf8, Module/binary>>;

        {oidc, Module@1} ->
            <<"oidc:"/utf8, Module@1/binary>>;

        {hybrid, Primary, Fallback} ->
            <<<<<<"hybrid:"/utf8, Primary/binary>>/binary, ":"/utf8>>/binary,
                Fallback/binary>>
    end.

-file("src/lightspeed/platform/foundation.gleam", 524).
-spec auth_seam_signature(auth_seam()) -> binary().
auth_seam_signature(Seam) ->
    <<<<<<<<<<<<<<<<(auth_provider_label(erlang:element(2, Seam)))/binary,
                                    "|override="/utf8>>/binary,
                                (override_point_label(erlang:element(3, Seam)))/binary>>/binary,
                            "|session_ttl="/utf8>>/binary,
                        (erlang:integer_to_binary(erlang:element(4, Seam)))/binary>>/binary,
                    "|mfa_required="/utf8>>/binary,
                (bool_label(erlang:element(5, Seam)))/binary>>/binary,
            "|passkey="/utf8>>/binary,
        (bool_label(erlang:element(6, Seam)))/binary>>.

-file("src/lightspeed/platform/foundation.gleam", 361).
?DOC(" Stable profile signature.\n").
-spec signature(app_profile()) -> binary().
signature(Profile) ->
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"profile:"/utf8,
                                                                (erlang:element(
                                                                    2,
                                                                    Profile
                                                                ))/binary>>/binary,
                                                            "|auth="/utf8>>/binary,
                                                        (auth_seam_signature(
                                                            erlang:element(
                                                                3,
                                                                Profile
                                                            )
                                                        ))/binary>>/binary,
                                                    "|admin="/utf8>>/binary,
                                                (admin_seam_signature(
                                                    erlang:element(4, Profile)
                                                ))/binary>>/binary,
                                            "|policy="/utf8>>/binary,
                                        (policy_seam_signature(
                                            erlang:element(5, Profile)
                                        ))/binary>>/binary,
                                    "|billing="/utf8>>/binary,
                                (billing_seam_signature(
                                    erlang:element(6, Profile)
                                ))/binary>>/binary,
                            "|surfaces="/utf8>>/binary,
                        (join_with(
                            <<","/utf8>>,
                            gleam@list:map(
                                erlang:element(7, Profile),
                                fun surface_label/1
                            )
                        ))/binary>>/binary,
                    "|workflows="/utf8>>/binary,
                (join_with(
                    <<","/utf8>>,
                    gleam@list:map(
                        erlang:element(8, Profile),
                        fun workflow_label/1
                    )
                ))/binary>>/binary,
            "|internal_patch="/utf8>>/binary,
        (bool_label(erlang:element(9, Profile)))/binary>>.

-file("src/lightspeed/platform/foundation.gleam", 381).
?DOC(" Stable integration-seam signature for extension contracts.\n").
-spec seam_contract_signature(app_profile()) -> binary().
seam_contract_signature(Profile) ->
    <<<<<<<<<<<<<<"auth_override="/utf8,
                                (override_point_label(
                                    erlang:element(
                                        3,
                                        erlang:element(3, Profile)
                                    )
                                ))/binary>>/binary,
                            "|admin_override="/utf8>>/binary,
                        (override_point_label(
                            erlang:element(3, erlang:element(4, Profile))
                        ))/binary>>/binary,
                    "|policy_override="/utf8>>/binary,
                (override_point_label(
                    erlang:element(3, erlang:element(5, Profile))
                ))/binary>>/binary,
            "|billing_override="/utf8>>/binary,
        (override_point_label(erlang:element(3, erlang:element(6, Profile))))/binary>>.

-file("src/lightspeed/platform/foundation.gleam", 393).
?DOC(" Stable workflow matrix signature.\n").
-spec workflow_matrix_signature(app_profile()) -> binary().
workflow_matrix_signature(Profile) ->
    Entries = gleam@list:map(
        required_workflows(),
        fun(Workflow) ->
            <<<<(workflow_label(Workflow))/binary, "="/utf8>>/binary,
                (bool_label(
                    workflow_runs_without_internal_patching(Profile, Workflow)
                ))/binary>>
        end
    ),
    <<<<<<"workflow_matrix:"/utf8, (erlang:element(2, Profile))/binary>>/binary,
            "|"/utf8>>/binary,
        (join_with(<<";"/utf8>>, Entries))/binary>>.