import type { IsolationFixture } from "./types.js";

const checkoutBaseline = {
  scenarioId: "checkout",
  identity: "scenario-checkout-v1",
  result: { status: "ok", total: 42, receiptId: "rcpt-001" },
};

const inventoryBaseline = {
  scenarioId: "inventory-sync",
  identity: "scenario-inventory-v1",
  result: { status: "synced", count: 7 },
};

export const isolationKnownGood: IsolationFixture = {
  fixtureId: "isolation/known-good",
  isolationVersion: "1.0",
  scenarios: [
    {
      scenarioId: "order-repetition-parallel-invariance",
      kind: "metamorphic-execution",
      baseline: checkoutBaseline,
      constraints: {
        orderInvariant: true,
        repetitionInvariant: true,
        parallelIndependent: true,
        stableIdentity: true,
      },
      orderings: [
        {
          orderingId: "forward",
          sequence: ["checkout", "inventory-sync"],
          observedResults: [checkoutBaseline, inventoryBaseline],
        },
        {
          orderingId: "reverse",
          sequence: ["inventory-sync", "checkout"],
          observedResults: [inventoryBaseline, checkoutBaseline],
        },
      ],
      repetitions: [
        {
          repetitionId: "triple-checkout",
          runCount: 3,
          observedResults: [checkoutBaseline, checkoutBaseline, checkoutBaseline],
        },
      ],
      parallelRuns: [
        {
          parallelId: "dual-checkout",
          contexts: [
            {
              contextId: "worker-a",
              scenarioId: "checkout",
              identity: checkoutBaseline.identity,
              result: checkoutBaseline.result,
            },
            {
              contextId: "worker-b",
              scenarioId: "checkout",
              identity: checkoutBaseline.identity,
              result: checkoutBaseline.result,
            },
          ],
        },
      ],
    },
    {
      scenarioId: "demo-mode-mock-only",
      kind: "mode-isolation",
      mode: "demo",
      isolationContract: {
        declaresIsolation: true,
        allowedDependencyTargets: ["mock-api", "local-fixture-db"],
      },
      accessAttempts: [
        {
          target: "mock-api",
          classification: "mock",
          reached: true,
          channel: "http",
        },
        {
          target: "local-fixture-db",
          classification: "local-fixture",
          reached: true,
          channel: "sql",
        },
        {
          target: "production-api",
          classification: "production",
          reached: false,
          channel: "http",
        },
      ],
    },
    {
      scenarioId: "offline-mode-no-live-deps",
      kind: "mode-isolation",
      mode: "offline",
      isolationContract: {
        declaresIsolation: true,
        allowedDependencyTargets: ["local-fixture-db"],
      },
      accessAttempts: [
        {
          target: "local-fixture-db",
          classification: "local-fixture",
          reached: true,
        },
      ],
    },
  ],
};
