{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nowtoprint.com/schemas/marketplace/problem-details.v1.schema.json",
  "title": "Marketplace Problem Details V1",
  "description": "RFC 9457 Problem Details with exact NowToPrint Marketplace code/type/title/status tuples.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "type",
    "title",
    "status",
    "code"
  ],
  "properties": {
    "type": {
      "type": "string",
      "format": "uri"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
    },
    "status": {
      "type": "integer",
      "minimum": 400,
      "maximum": 599
    },
    "code": {
      "type": "string",
      "enum": [
        "invalid_request",
        "validation_failed",
        "unauthenticated",
        "forbidden",
        "not_found",
        "conflict",
        "precondition_required",
        "too_early",
        "payload_too_large",
        "length_required",
        "gone",
        "unsupported_media_type",
        "revision_conflict",
        "idempotency_conflict",
        "rate_limited",
        "unavailable",
        "bad_gateway",
        "gateway_timeout",
        "internal_error"
      ]
    },
    "detail": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1000,
      "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
    },
    "instance": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048,
      "pattern": "^/(?!/)(?![\\s\\S]*\\\\)(?![\\s\\S]*[\\u0000-\\u001F\\u007F])[\\s\\S]*$"
    },
    "requestId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
    },
    "reasonCode": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^[A-Za-z][A-Za-z0-9_.:-]*$"
    },
    "canonicalEndpoint": {
      "type": "string",
      "minLength": 18,
      "maxLength": 2048,
      "pattern": "^/api/marketplace/(?![\\s\\S]*[?#])(?![\\s\\S]*\\\\)(?![\\s\\S]*[\\u0000-\\u001F\\u007F])[\\s\\S]+$"
    },
    "errors": {
      "type": "array",
      "maxItems": 100,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "path",
          "code",
          "message"
        ],
        "properties": {
          "path": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
          },
          "code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
          },
          "message": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000,
            "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
          }
        }
      }
    },
    "abuseSignals": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "decisionId": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "entitlementReason": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "evidenceRequired": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "evidenceSummary": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "expectedAmount": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "marketplaceDecision": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "marketplaceProductionHold": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "marketplaceProductionRelease": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "newPaymentStatus": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "orderId": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "reason": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "reasons": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "recoveryState": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "requiredNextStep": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "retryAfter": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "retryAfterMs": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "retryable": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "rfqId": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "riskSignals": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "target": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "tokenReason": {
      "$ref": "#/$defs/publicExtensionValue"
    },
    "verifiedAmount": {
      "$ref": "#/$defs/publicExtensionValue"
    }
  },
  "$defs": {
    "publicExtensionValue": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "boolean"
        },
        {
          "type": "number"
        },
        {
          "type": "string",
          "maxLength": 4000
        },
        {
          "type": "array",
          "maxItems": 100,
          "items": {
            "$ref": "#/$defs/publicExtensionValue"
          }
        },
        {
          "type": "object",
          "maxProperties": 50,
          "propertyNames": {
            "minLength": 1,
            "maxLength": 100,
            "not": {
              "enum": [
                "__proto__",
                "constructor",
                "prototype"
              ]
            }
          },
          "additionalProperties": {
            "$ref": "#/$defs/publicExtensionValue"
          }
        }
      ]
    }
  },
  "oneOf": [
    {
      "properties": {
        "code": {
          "const": "invalid_request"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/invalid-request"
        },
        "title": {
          "const": "Invalid Marketplace request"
        },
        "status": {
          "const": 400
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "validation_failed"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/validation-failed"
        },
        "title": {
          "const": "Marketplace request validation failed"
        },
        "status": {
          "const": 422
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "unauthenticated"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/unauthenticated"
        },
        "title": {
          "const": "Marketplace authentication required"
        },
        "status": {
          "const": 401
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "forbidden"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/forbidden"
        },
        "title": {
          "const": "Marketplace action forbidden"
        },
        "status": {
          "const": 403
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "not_found"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/not-found"
        },
        "title": {
          "const": "Marketplace resource not found"
        },
        "status": {
          "const": 404
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "conflict"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/conflict"
        },
        "title": {
          "const": "Marketplace resource conflict"
        },
        "status": {
          "const": 409
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "precondition_required"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/precondition-required"
        },
        "title": {
          "const": "Marketplace request precondition required"
        },
        "status": {
          "const": 428
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "too_early"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/too-early"
        },
        "title": {
          "const": "Marketplace request is still being processed"
        },
        "status": {
          "const": 425
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "payload_too_large"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/payload-too-large"
        },
        "title": {
          "const": "Marketplace request payload too large"
        },
        "status": {
          "const": 413
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "length_required"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/length-required"
        },
        "title": {
          "const": "Marketplace request content length required"
        },
        "status": {
          "const": 411
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "gone"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/gone"
        },
        "title": {
          "const": "Marketplace resource is no longer available"
        },
        "status": {
          "const": 410
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "unsupported_media_type"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/unsupported-media-type"
        },
        "title": {
          "const": "Marketplace request media type is unsupported"
        },
        "status": {
          "const": 415
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "revision_conflict"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/revision-conflict"
        },
        "title": {
          "const": "Marketplace resource revision conflict"
        },
        "status": {
          "const": 409
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "idempotency_conflict"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/idempotency-conflict"
        },
        "title": {
          "const": "Marketplace idempotency conflict"
        },
        "status": {
          "const": 409
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "rate_limited"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/rate-limited"
        },
        "title": {
          "const": "Marketplace request rate limited"
        },
        "status": {
          "const": 429
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "unavailable"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/unavailable"
        },
        "title": {
          "const": "Marketplace service unavailable"
        },
        "status": {
          "const": 503
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "bad_gateway"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/bad-gateway"
        },
        "title": {
          "const": "Marketplace dependency returned an invalid response"
        },
        "status": {
          "const": 502
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "gateway_timeout"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/gateway-timeout"
        },
        "title": {
          "const": "Marketplace dependency timed out"
        },
        "status": {
          "const": 504
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    },
    {
      "properties": {
        "code": {
          "const": "internal_error"
        },
        "type": {
          "const": "https://nowtoprint.com/problems/marketplace/internal-error"
        },
        "title": {
          "const": "Marketplace request failed"
        },
        "status": {
          "const": 500
        }
      },
      "required": [
        "code",
        "type",
        "title",
        "status"
      ]
    }
  ],
  "x-contract-authority": "apps/web/src/lib/marketplace/marketplace-problem-details.ts#MARKETPLACE_PROBLEM_REGISTRY"
}
