{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uqp.dev/spec/schemas/common.json",
  "title": "UQP reusable definitions",
  "$defs": {
    "identifier": {
      "type": "string",
      "minLength": 1
    },
    "consent": {
      "type": "object",
      "properties": {
        "share_for_pricing_research": {
          "type": "boolean"
        },
        "anonymize": {
          "type": "boolean"
        },
        "captured_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "share_for_pricing_research",
        "anonymize",
        "captured_at"
      ],
      "additionalProperties": false
    },
    "answers": {
      "type": "object",
      "propertyNames": {
        "not": {
          "enum": [
            "email",
            "phone",
            "name",
            "first_name",
            "last_name",
            "full_name",
            "address",
            "contact",
            "contact_details",
            "date_of_birth"
          ]
        }
      },
      "additionalProperties": true
    },
    "currencies": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[A-Z]{3}$"
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "reviewMode": {
      "enum": [
        "pre_price",
        "post_price"
      ]
    },
    "expiryDays": {
      "type": "integer",
      "minimum": 1
    },
    "packId": {
      "type": "string",
      "minLength": 1
    },
    "packVersion": {
      "type": "string",
      "minLength": 1
    },
    "priceRange": {
      "type": "object",
      "properties": {
        "min": {
          "type": "number",
          "minimum": 0
        },
        "max": {
          "type": "number",
          "minimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "basis": {
          "enum": [
            "hourly",
            "day_rate",
            "from",
            "fixed"
          ]
        },
        "method": {
          "enum": [
            "artist_stated",
            "rule",
            "logged_quotes"
          ]
        },
        "n": {
          "type": "integer",
          "minimum": 5
        },
        "provenance": {
          "$ref": "#/$defs/provenance"
        },
        "min_minor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "max_minor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "min",
        "max",
        "currency",
        "basis",
        "method",
        "provenance"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "method": {
                "const": "logged_quotes"
              }
            },
            "required": [
              "method"
            ]
          },
          "then": {
            "required": [
              "n"
            ],
            "properties": {
              "n": {}
            }
          }
        }
      ]
    },
    "deposit": {
      "type": "object",
      "description": "Provider is merchant of record; UQP never holds funds. Only processor confirmation marks a deposit paid.",
      "properties": {
        "amount": {
          "type": "number",
          "minimum": 0
        },
        "basis": {
          "type": "string",
          "minLength": 1
        },
        "policies": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "status": {
          "enum": [
            "unpaid",
            "paid"
          ]
        },
        "merchant_of_record": {
          "const": "provider"
        },
        "confirmation": {
          "type": "object",
          "properties": {
            "source": {
              "const": "payment_processor"
            },
            "reference": {
              "type": "string",
              "minLength": 1
            },
            "confirmed_at": {
              "type": "string",
              "format": "date-time"
            }
          },
          "required": [
            "source",
            "reference",
            "confirmed_at"
          ],
          "additionalProperties": false
        },
        "provenance": {
          "$ref": "#/$defs/provenance"
        },
        "amount_minor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "capture_on": {
          "enum": [
            "accept",
            "booking",
            "immediate"
          ]
        },
        "refundable_until": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "policy_url": {
          "type": "string",
          "format": "uri"
        }
      },
      "required": [
        "amount",
        "basis",
        "policies",
        "status",
        "merchant_of_record",
        "provenance"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "paid"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "required": [
              "confirmation"
            ],
            "properties": {
              "confirmation": {}
            }
          },
          "else": {
            "not": {
              "required": [
                "confirmation"
              ],
              "properties": {
                "confirmation": {}
              }
            }
          }
        }
      ]
    },
    "clientApproval": {
      "type": "object",
      "properties": {
        "amount": {
          "type": "number",
          "minimum": 0
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "policies": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "approved_amount": {
          "const": true
        },
        "approved_policies": {
          "const": true
        },
        "approved_at": {
          "type": "string",
          "format": "date-time"
        },
        "amount_minor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "amount",
        "currency",
        "policies",
        "approved_amount",
        "approved_policies",
        "approved_at"
      ],
      "additionalProperties": false
    },
    "provenance": {
      "type": "object",
      "properties": {
        "who": {
          "type": "string",
          "minLength": 1
        },
        "when": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "who",
        "when"
      ],
      "additionalProperties": false
    },
    "quantity": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "quantityUnit": {
      "type": "object",
      "description": "Rec 20 unit descriptor. Quantity counts steps of 10^-scale units; omitted scale means zero.",
      "properties": {
        "unit": {
          "enum": [
            "C62",
            "INH",
            "CMT",
            "FTK",
            "MTK",
            "HUR",
            "MIN"
          ]
        },
        "scale": {
          "type": "integer",
          "minimum": 0,
          "maximum": 15,
          "default": 0
        },
        "display_text": {
          "type": "string"
        }
      },
      "required": [
        "unit",
        "display_text"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "unit": {
                "const": "C62"
              }
            },
            "required": [
              "unit"
            ]
          },
          "then": {
            "properties": {
              "scale": {
                "const": 0
              }
            }
          }
        }
      ]
    },
    "attribution": {
      "type": "object",
      "description": "Neutral routing attribution; not payment authorization or proof of consent.",
      "properties": {
        "referrer_id": {
          "type": "string"
        },
        "token": {
          "type": "string"
        },
        "campaign": {
          "type": "string"
        },
        "source": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "routingPolicy": {
      "type": "object",
      "properties": {
        "allow_stateless_estimate": {
          "type": "boolean"
        },
        "require_human_quote_review": {
          "type": "boolean"
        },
        "max_concurrent_quote_holds": {
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false
    },
    "checkoutHandoff": {
      "type": "object",
      "description": "Reference handoff metadata, not payment execution. Draft proposal mappings are subject to change; no conformance claim.",
      "properties": {
        "protocol": {
          "enum": [
            "ucp",
            "acp"
          ]
        },
        "url": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "ucp_quote_status": {
          "enum": [
            "pending",
            "quoted",
            "accepted",
            "declined",
            "expired",
            "withdrawn"
          ]
        },
        "acp_quote_id": {
          "type": "string"
        },
        "quote_expires_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "required": [
        "protocol",
        "url"
      ],
      "additionalProperties": false
    }
  }
}
