{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/buyrecord-app/json-schema/buyrecord-app-outcome-submission-schema.json",
  "title": "OutcomeSubmission",
  "x-generated": "2026-11-03",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/buyrecord-app-openapi.json#/components/schemas/OutcomeSubmission",
  "properties": {
    "product_id": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ],
      "title": "Product Id",
      "description": "BuyRecord product id. Either this or product_url."
    },
    "product_url": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 500,
          "pattern": "^https://"
        },
        {
          "type": "null"
        }
      ],
      "title": "Product Url",
      "description": "The product page URL at the store. Either this or product_id."
    },
    "outcome": {
      "type": "string",
      "enum": [
        "kept_silent",
        "kept_positive",
        "complained",
        "returned"
      ],
      "title": "Outcome"
    },
    "reasons": {
      "items": {
        "type": "string",
        "enum": [
          "size",
          "quality",
          "not_as_described",
          "late_delivery",
          "damaged",
          "other"
        ]
      },
      "type": "array",
      "maxItems": 6,
      "title": "Reasons"
    },
    "proof": {
      "oneOf": [
        {
          "$ref": "#/$defs/PaymentReceiptProof"
        },
        {
          "$ref": "#/$defs/ShopifyOrderProof"
        },
        {
          "$ref": "#/$defs/EmailReceiptProof"
        }
      ],
      "title": "Proof"
    }
  },
  "type": "object",
  "required": [
    "outcome",
    "proof"
  ],
  "$defs": {
    "EmailReceiptProof": {
      "properties": {
        "type": {
          "type": "string",
          "const": "email_receipt",
          "title": "Type"
        },
        "raw_email_base64": {
          "type": "string",
          "maxLength": 2800000,
          "title": "Raw Email Base64",
          "description": "The merchant's original order confirmation email (.eml, RFC 5322), base64-encoded. Its DKIM signature is verified; the email is processed in memory and never stored."
        },
        "order_number": {
          "type": "string",
          "maxLength": 60,
          "minLength": 1,
          "title": "Order Number",
          "description": "Order number as it appears in the email."
        },
        "product_name": {
          "type": "string",
          "maxLength": 200,
          "minLength": 3,
          "title": "Product Name",
          "description": "Product name exactly as it appears in the email."
        }
      },
      "type": "object",
      "required": [
        "type",
        "raw_email_base64",
        "order_number",
        "product_name"
      ],
      "title": "EmailReceiptProof"
    },
    "PaymentReceiptProof": {
      "properties": {
        "type": {
          "type": "string",
          "const": "payment_receipt",
          "title": "Type"
        },
        "reference": {
          "type": "string",
          "maxLength": 200,
          "minLength": 4,
          "title": "Reference",
          "description": "Receipt or transaction reference. Hashed on arrival, never stored."
        },
        "purchased_on": {
          "type": "string",
          "format": "date",
          "title": "Purchased On"
        }
      },
      "type": "object",
      "required": [
        "type",
        "reference",
        "purchased_on"
      ],
      "title": "PaymentReceiptProof"
    },
    "ShopifyOrderProof": {
      "properties": {
        "type": {
          "type": "string",
          "const": "shopify_order",
          "title": "Type"
        },
        "shop_domain": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9.-]{1,253}$",
          "title": "Shop Domain",
          "description": "The store's domain, e.g. brand.com or brand.myshopify.com."
        },
        "order_number": {
          "type": "string",
          "pattern": "^#?[A-Za-z0-9-]{1,40}$",
          "title": "Order Number",
          "description": "Order number as shown to the buyer, e.g. #1001. Never stored."
        },
        "confirmation_number": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]{6,20}$",
          "title": "Confirmation Number",
          "description": "Order confirmation number from the order confirmation, e.g. XPLZ3K9HG. Never stored."
        }
      },
      "type": "object",
      "required": [
        "type",
        "shop_domain",
        "order_number",
        "confirmation_number"
      ],
      "title": "ShopifyOrderProof"
    }
  }
}