/**
 * Feature-flag gate (`config/profiles` `features.wertstromScenarios`) — pure
 * predicate, same shape/testability as `copilotExportsGate`
 * (lib/copilot-export/internal/ai-instruction-block.ts): the caller resolves
 * the flag via getProfile() and passes the boolean in, so this stays
 * testable without booting a composition profile. Review-Fix F2
 * (adversarial review, PR #353): the A9-Erstellungs-UI this gate guards is
 * P5-scoped per CAPABILITY-MATRIX.md (P2 only owns the Szenarien
 * DATENMODELL — the `scenario_kind`/`parent_value_stream_id` columns, Zod,
 * engine — not the create-action itself), and the matrix requires a flag for
 * P5. `false` in every profile until P5 ships.
 *
 * Lives in lib/api (not in the route file): Next.js route modules only
 * permit HTTP-method/config exports — an extra named export fails the
 * route-types check in `next build`, which tsc alone does not catch.
 */
export function wertstromScenariosGate(enabled: boolean): { ok: true } | { ok: false; error: string } {
  if (!enabled) {
    return { ok: false, error: 'Szenarien-Erstellung ist für dieses Deployment nicht aktiviert.' }
  }
  return { ok: true }
}

/**
 * Feature-flag gate (`config/profiles` `features.wertstromUxV2`) — Wertstrom
 * P3 (KAR-878/KAR-986, CAPABILITY-MATRIX.md A1/A2/A4 "das UX-Herz": Quick-
 * Start-Wizard, Auto-Layout, Timeline-Leiter v2). Same pure/testable shape as
 * `wertstromScenariosGate` above (Phasenplan-Pflicht: P3 requires a flag,
 * `false` in every profile until this phase is rolled out).
 *
 * Unlike `wertstromScenariosGate`, this phase adds no NEW mutating route to
 * enforce it in: the wizard's "Fertigstellen" step deliberately reuses the
 * existing, UNGATED `POST /api/wertstrom` + `PUT /api/wertstrom/[id]`
 * primitives verbatim (same endpoints the plain "Neue Wertstromanalyse"
 * create-modal and the plain editor's Speichern button already call
 * unconditionally) — see PRODUCT_SPEC.md P3 section "Scope-Entscheidung:
 * kein neuer Endpunkt". A wizard-built Wertstrom is structurally ordinary
 * (nodes/connections/layout a user could always have built by hand in the
 * existing editor); gating those shared routes would incorrectly also block
 * the pre-existing plain-create/save flows when the flag is off. So this
 * gate is the SINGLE source of truth both `page.tsx` server components use
 * to resolve the `wertstromUxV2Enabled` prop (unlike wertstromScenariosGate,
 * which only guards its route — the P2 prop reads the raw flag directly) —
 * kept here, not inlined, so a future phase that DOES add a dedicated route
 * (or needs a second call site) has one predicate to import, not two
 * definitions to keep in sync.
 */
export function wertstromUxV2Gate(enabled: boolean): { ok: true } | { ok: false; error: string } {
  if (!enabled) {
    return { ok: false, error: 'Der Wertstrom-Assistent ist für dieses Deployment nicht aktiviert.' }
  }
  return { ok: true }
}

/**
 * Feature-flag gate (`config/profiles` `features.wertstromSimvsmImport`) —
 * Wertstrom P6 (KAR-878/KAR-986, execution-prompt §14, Capability-Matrix
 * A16: SimVSM-Import-Adapter). Same pure/testable shape as
 * `wertstromScenariosGate`/`wertstromUxV2Gate` above (Phasenplan-Pflicht,
 * `false` in every profile until this phase is rolled out).
 *
 * Guards BOTH new routes (`app/api/wertstrom/import/preview`,
 * `.../confirm`) — each calls this first, before any auth/DB work, and
 * returns `apiError.notFound()` on `!ok` (same "route ohne Flag ⇒ 404"
 * convention `app/api/wertstrom/[id]/duplicate/route.ts` already uses for
 * `wertstromScenariosGate`, not 403 — a disabled route should look
 * indistinguishable from a route that doesn't exist). The Wertstrom-Liste's
 * "SimVSM importieren" entry point reads the same flag via a
 * server-resolved `wertstromSimvsmImportEnabled` prop (app/wertstrom/page.tsx),
 * matching `wertstromUxV2Enabled`'s convention.
 */
export function wertstromSimvsmImportGate(enabled: boolean): { ok: true } | { ok: false; error: string } {
  if (!enabled) {
    return { ok: false, error: 'Der SimVSM-Import ist für dieses Deployment nicht aktiviert.' }
  }
  return { ok: true }
}
