{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pdf2html.invalid/quality/job-lifecycle/public-error-case.schema.json",
  "title": "Canonical public error projection fixture",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "case_id",
    "title",
    "internal",
    "expected"
  ],
  "properties": {
    "case_id": {
      "type": "string",
      "pattern": "^JE-00[1-7]$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "internal": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "condition",
        "detail"
      ],
      "properties": {
        "condition": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]+$"
        },
        "detail": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        }
      }
    },
    "expected": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "body",
        "forbidden_fragments",
        "evidence"
      ],
      "properties": {
        "status": {
          "enum": [
            401,
            404,
            409,
            410,
            413
          ]
        },
        "body": {
          "$ref": "#/$defs/envelope"
        },
        "forbidden_fragments": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          }
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          }
        }
      }
    }
  },
  "$defs": {
    "envelope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "version",
        "request_id",
        "error"
      ],
      "properties": {
        "version": {
          "const": "2026-08-23"
        },
        "request_id": {
          "type": "string",
          "format": "uuid"
        },
        "error": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "code",
            "message",
            "retryable",
            "field_errors"
          ],
          "properties": {
            "code": {
              "enum": [
                "AUTH_REQUIRED",
                "INSUFFICIENT_CREDITS",
                "UPLOAD_REJECTED",
                "ARTIFACT_EXPIRED",
                "NOT_FOUND",
                "IDEMPOTENCY_CONFLICT",
                "STATE_CONFLICT"
              ]
            },
            "message": {
              "enum": [
                "Authentication required",
                "Insufficient credits",
                "Upload rejected",
                "Artifact expired",
                "Resource not found",
                "Idempotency conflict",
                "State conflict"
              ]
            },
            "retryable": {
              "const": false
            },
            "field_errors": {
              "type": "object",
              "maxProperties": 0,
              "additionalProperties": false
            }
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "case_id": {
            "const": "JE-001"
          }
        },
        "required": [
          "case_id"
        ]
      },
      "then": {
        "properties": {
          "expected": {
            "properties": {
              "status": {
                "const": 401
              },
              "body": {
                "properties": {
                  "error": {
                    "properties": {
                      "code": {
                        "const": "AUTH_REQUIRED"
                      },
                      "message": {
                        "const": "Authentication required"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "case_id": {
            "const": "JE-002"
          }
        },
        "required": [
          "case_id"
        ]
      },
      "then": {
        "properties": {
          "expected": {
            "properties": {
              "status": {
                "const": 409
              },
              "body": {
                "properties": {
                  "error": {
                    "properties": {
                      "code": {
                        "const": "INSUFFICIENT_CREDITS"
                      },
                      "message": {
                        "const": "Insufficient credits"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "case_id": {
            "const": "JE-003"
          }
        },
        "required": [
          "case_id"
        ]
      },
      "then": {
        "properties": {
          "expected": {
            "properties": {
              "status": {
                "const": 413
              },
              "body": {
                "properties": {
                  "error": {
                    "properties": {
                      "code": {
                        "const": "UPLOAD_REJECTED"
                      },
                      "message": {
                        "const": "Upload rejected"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "case_id": {
            "const": "JE-004"
          }
        },
        "required": [
          "case_id"
        ]
      },
      "then": {
        "properties": {
          "expected": {
            "properties": {
              "status": {
                "const": 410
              },
              "body": {
                "properties": {
                  "error": {
                    "properties": {
                      "code": {
                        "const": "ARTIFACT_EXPIRED"
                      },
                      "message": {
                        "const": "Artifact expired"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "case_id": {
            "const": "JE-005"
          }
        },
        "required": [
          "case_id"
        ]
      },
      "then": {
        "properties": {
          "expected": {
            "properties": {
              "status": {
                "const": 404
              },
              "body": {
                "properties": {
                  "error": {
                    "properties": {
                      "code": {
                        "const": "NOT_FOUND"
                      },
                      "message": {
                        "const": "Resource not found"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "case_id": {
            "const": "JE-006"
          }
        },
        "required": [
          "case_id"
        ]
      },
      "then": {
        "properties": {
          "expected": {
            "properties": {
              "status": {
                "const": 409
              },
              "body": {
                "properties": {
                  "error": {
                    "properties": {
                      "code": {
                        "const": "IDEMPOTENCY_CONFLICT"
                      },
                      "message": {
                        "const": "Idempotency conflict"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "case_id": {
            "const": "JE-007"
          }
        },
        "required": [
          "case_id"
        ]
      },
      "then": {
        "properties": {
          "expected": {
            "properties": {
              "status": {
                "const": 409
              },
              "body": {
                "properties": {
                  "error": {
                    "properties": {
                      "code": {
                        "const": "STATE_CONFLICT"
                      },
                      "message": {
                        "const": "State conflict"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  ]
}
