{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pdf2html.invalid/quality/storage-lifecycle/case.schema.json",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "caseId",
    "category",
    "description",
    "operation",
    "input",
    "expected"
  ],
  "properties": {
    "caseId": {
      "type": "string",
      "pattern": "^SL-[0-9]{3}$"
    },
    "category": {
      "enum": [
        "archive_layout",
        "bucket",
        "deadline",
        "delivery",
        "library",
        "object_key",
        "ownership",
        "reconciliation",
        "signed_url"
      ]
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "operation": {
      "enum": [
        "authorize_download",
        "derive_deadline",
        "evaluate_expiry",
        "issue_signed_url",
        "project_library",
        "reconcile_objects",
        "validate_archive",
        "validate_bucket",
        "validate_delivery",
        "validate_object_key"
      ]
    },
    "input": {
      "type": "object"
    },
    "expected": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "outcome",
        "httpStatus",
        "error",
        "state",
        "calls",
        "mutations"
      ],
      "properties": {
        "outcome": {
          "enum": [
            "accepted",
            "rejected",
            "denied",
            "blocked",
            "noop",
            "reconcile"
          ]
        },
        "httpStatus": {
          "type": "integer",
          "minimum": 100,
          "maximum": 599
        },
        "error": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "code",
                "message"
              ],
              "properties": {
                "code": {
                  "type": "string",
                  "pattern": "^[A-Z][A-Z0-9_]+$"
                },
                "message": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          ]
        },
        "state": {
          "type": "object"
        },
        "calls": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "service",
              "method",
              "count"
            ],
            "properties": {
              "service": {
                "enum": [
                  "database",
                  "storage",
                  "signer"
                ]
              },
              "method": {
                "type": "string",
                "minLength": 1
              },
              "count": {
                "type": "integer",
                "minimum": 0
              },
              "arguments": {
                "type": "object"
              }
            }
          }
        },
        "mutations": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "entity",
              "action",
              "count"
            ],
            "properties": {
              "entity": {
                "type": "string",
                "minLength": 1
              },
              "action": {
                "type": "string",
                "minLength": 1
              },
              "count": {
                "type": "integer",
                "minimum": 0
              },
              "value": {}
            }
          }
        }
      }
    }
  },
  "allOf": [
    {
      "oneOf": [
        {
          "properties": {
            "operation": {
              "const": "authorize_download"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "conversionExists",
                "now",
                "objectOwnerId",
                "objectState",
                "sessionUserId",
                "zipExpiresAt"
              ],
              "properties": {
                "conversionExists": {
                  "type": "boolean"
                },
                "now": {
                  "type": "string",
                  "format": "date-time"
                },
                "objectOwnerId": {
                  "type": "string",
                  "format": "uuid"
                },
                "objectState": {
                  "type": "string"
                },
                "sessionUserId": {
                  "type": [
                    "null",
                    "string"
                  ],
                  "format": "uuid"
                },
                "zipExpiresAt": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "derive_deadline"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "anchorAt",
                "kind"
              ],
              "properties": {
                "anchorAt": {
                  "type": [
                    "integer",
                    "null",
                    "string"
                  ]
                },
                "irrelevantTimes": {
                  "type": "array"
                },
                "kind": {
                  "type": "string"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "evaluate_expiry"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "expiresAt",
                "kind",
                "now"
              ],
              "properties": {
                "expiresAt": {
                  "type": "string",
                  "format": "date-time"
                },
                "kind": {
                  "type": "string"
                },
                "now": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "issue_signed_url"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "configuredTtlSeconds",
                "conversionExists",
                "key",
                "method",
                "now",
                "objectOwnerId",
                "objectState",
                "sessionUserId",
                "zipExpiresAt"
              ],
              "properties": {
                "configuredTtlSeconds": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "conversionExists": {
                  "type": "boolean"
                },
                "key": {
                  "type": "string",
                  "minLength": 1
                },
                "method": {
                  "type": "string"
                },
                "now": {
                  "type": "string",
                  "format": "date-time"
                },
                "objectOwnerId": {
                  "type": "string",
                  "format": "uuid"
                },
                "objectState": {
                  "type": "string"
                },
                "sessionUserId": {
                  "type": "string",
                  "format": "uuid"
                },
                "zipExpiresAt": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "project_library"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "balance",
                "now",
                "rows",
                "viewerId"
              ],
              "properties": {
                "balance": {
                  "type": "integer"
                },
                "now": {
                  "type": "string",
                  "format": "date-time"
                },
                "rows": {
                  "type": "array"
                },
                "viewerId": {
                  "type": "string"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "reconcile_objects"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "batchSize",
                "dbState",
                "deadline",
                "events",
                "namespacePrefix",
                "now",
                "objectState"
              ],
              "properties": {
                "batchSize": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "dbState": {
                  "type": "string"
                },
                "deadline": {
                  "type": "string",
                  "format": "date-time"
                },
                "dueCount": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "events": {
                  "type": "array"
                },
                "namespacePrefix": {
                  "type": "string",
                  "minLength": 1
                },
                "now": {
                  "type": "string",
                  "format": "date-time"
                },
                "objectState": {
                  "type": "string"
                },
                "pages": {
                  "type": "array"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "validate_archive"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "destinationOnly",
                "entries",
                "externalDependencies",
                "manifestValid",
                "referencesValid",
                "withinCeilings"
              ],
              "properties": {
                "destinationOnly": {
                  "type": "boolean"
                },
                "entries": {
                  "type": "array"
                },
                "externalDependencies": {
                  "type": "array"
                },
                "manifestValid": {
                  "type": "boolean"
                },
                "referencesValid": {
                  "type": "boolean"
                },
                "withinCeilings": {
                  "type": "boolean"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "validate_bucket"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "adapterState",
                "anonymousGetAllowed",
                "anonymousListAllowed",
                "blockPublicAcls",
                "blockPublicPolicy",
                "crossOwnerPrefixAllowed",
                "lifecycleMappingsValid"
              ],
              "properties": {
                "adapterState": {
                  "type": "string"
                },
                "anonymousGetAllowed": {
                  "type": "boolean"
                },
                "anonymousListAllowed": {
                  "type": "boolean"
                },
                "blockPublicAcls": {
                  "type": "boolean"
                },
                "blockPublicPolicy": {
                  "type": "boolean"
                },
                "crossOwnerPrefixAllowed": {
                  "type": "boolean"
                },
                "lifecycleMappingsValid": {
                  "type": "boolean"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "validate_delivery"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "dtoContainsRawKey",
                "externalDependencies",
                "publicRoutes",
                "representations"
              ],
              "properties": {
                "dtoContainsRawKey": {
                  "type": "boolean"
                },
                "externalDependencies": {
                  "type": "array"
                },
                "publicRoutes": {
                  "type": "array"
                },
                "representations": {
                  "type": "array"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        },
        {
          "properties": {
            "operation": {
              "const": "validate_object_key"
            },
            "input": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "key",
                "kind",
                "ownerId"
              ],
              "properties": {
                "attemptNo": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "conversionId": {
                  "type": "string",
                  "format": "uuid"
                },
                "key": {
                  "type": "string",
                  "minLength": 1
                },
                "kind": {
                  "type": "string"
                },
                "ownerId": {
                  "type": "string",
                  "format": "uuid"
                },
                "uploadId": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "required": [
            "operation",
            "input"
          ]
        }
      ]
    }
  ]
}
