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

export const decoderKnownGood: DecoderFixture = {
  fixtureId: "decoder/known-good",
  scenarios: [
    {
      scenarioId: "reject-empty-coercion",
      kind: "integer",
      input: "",
      constraints: {
        rejectEmptyCoercion: true,
        decimalIntegerOnly: true,
        safeIntegerOnly: true,
      },
      observation: {
        accepted: false,
        error: { kind: "decoder-empty-input", message: "empty string cannot coerce to integer" },
      },
    },
    {
      scenarioId: "reject-null-coercion",
      kind: "integer",
      input: null,
      constraints: {
        rejectNullCoercion: true,
        decimalIntegerOnly: true,
      },
      observation: {
        accepted: false,
        error: { kind: "decoder-null-input", message: "null cannot coerce to integer" },
      },
    },
    {
      scenarioId: "reject-hex-syntax",
      kind: "integer",
      input: "0x10",
      constraints: { decimalIntegerOnly: true },
      observation: {
        accepted: false,
        error: { kind: "decoder-unsupported-syntax", message: "hex notation not allowed" },
      },
    },
    {
      scenarioId: "reject-unsafe-integer",
      kind: "integer",
      input: "9007199254740993",
      constraints: { decimalIntegerOnly: true, safeIntegerOnly: true },
      observation: {
        accepted: false,
        error: { kind: "decoder-unsafe-integer", message: "integer outside safe range" },
      },
    },
    {
      scenarioId: "reject-malformed-date",
      kind: "date",
      input: "not-a-date",
      malformed: true,
      constraints: { rejectMalformedDate: true },
      observation: {
        accepted: false,
        error: { kind: "decoder-malformed-date", message: "malformed date input" },
      },
    },
    {
      scenarioId: "fallback-selects-valid-secondary",
      kind: "fallback",
      candidates: [
        { value: "invalid", valid: false },
        { value: 7, valid: true },
      ],
      selectedIndex: 1,
      constraints: {},
      observation: { accepted: true, value: 7 },
    },
    {
      scenarioId: "idempotent-canonicalization",
      kind: "canonicalization",
      passes: {
        input: "User-Name",
        firstPass: "user_name",
        secondPass: "user_name",
        decodeAfterCanonicalize: "User-Name",
      },
      constraints: { idempotent: true, reversible: true, collisionSafe: true },
    },
    {
      scenarioId: "distinct-sentinel",
      kind: "sentinel",
      sentinel: {
        state: "missing",
        decodedAs: null,
        validValues: [1, 2, 3],
      },
      constraints: {},
    },
    {
      scenarioId: "typed-decoder-error",
      kind: "error-boundary",
      input: { corrupt: true },
      constraints: {},
      driverException: "PgError: invalid input syntax for type integer",
      observation: {
        accepted: false,
        error: {
          kind: "decoder-invalid-input",
          message: "integer input is invalid",
        },
      },
    },
  ],
};
