{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://splitclubapp.com/schemas/v1/price_tier.json",
  "title": "PriceTier",
  "description": "How an offering is priced: an amount per person, group, hour or unit, with optional fees, deposit and minimum spend.",
  "x-doc": "schema-price-tier",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "amount",
    "currency",
    "unit"
  ],
  "properties": {
    "external_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[^\\s]+$",
      "description": "Your system's id for this object. Sending the same external_id again updates or replays it; it never makes a second one.",
      "x-expected": "your own id for it, 1–128 characters, no spaces",
      "examples": [
        "tee-sheet-4471"
      ]
    },
    "label": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "examples": [
        "Weekday twilight"
      ]
    },
    "amount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100000000,
      "description": "Money in integer minor units (cents for usd): 14500 is $145.00.",
      "x-expected": "an integer in minor units (e.g. 14500 for $145.00)",
      "examples": [
        14500
      ]
    },
    "currency": {
      "type": "string",
      "pattern": "^[a-z]{3}$",
      "description": "ISO 4217 currency code, lower case.",
      "x-expected": "a three-letter ISO 4217 code in lower case (e.g. \"usd\")",
      "examples": [
        "usd"
      ]
    },
    "unit": {
      "type": "string",
      "enum": [
        "per_person",
        "per_group",
        "per_hour",
        "per_unit"
      ]
    },
    "min_party": {
      "type": "integer",
      "minimum": 1,
      "maximum": 500,
      "examples": [
        2
      ]
    },
    "max_party": {
      "type": "integer",
      "minimum": 1,
      "maximum": 500,
      "examples": [
        4
      ]
    },
    "days": {
      "type": "array",
      "maxItems": 7,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "enum": [
          "mon",
          "tue",
          "wed",
          "thu",
          "fri",
          "sat",
          "sun"
        ]
      },
      "description": "Days of the week this tier applies to; every day when absent.",
      "examples": [
        [
          "mon",
          "tue",
          "wed",
          "thu"
        ]
      ]
    },
    "time_window": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "from",
        "to"
      ],
      "properties": {
        "from": {
          "type": "string",
          "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$",
          "x-expected": "a local time, HH:MM",
          "examples": [
            "15:00"
          ]
        },
        "to": {
          "type": "string",
          "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$",
          "x-expected": "a local time, HH:MM",
          "examples": [
            "19:00"
          ]
        }
      },
      "description": "Local start times this tier applies to (e.g. twilight from 15:00).",
      "examples": [
        {
          "from": "15:00",
          "to": "19:00"
        }
      ]
    },
    "fees": {
      "type": "array",
      "maxItems": 10,
      "items": {
        "$ref": "#/$defs/fee"
      }
    },
    "deposit": {
      "$ref": "#/$defs/deposit"
    },
    "minimum_spend": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100000000,
      "description": "A minimum spend for the party, in minor units (tables, cabanas).",
      "x-expected": "an integer in minor units (e.g. 14500 for $145.00)",
      "examples": [
        14500
      ]
    }
  },
  "$defs": {
    "fee": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "included"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "service",
            "tax",
            "gratuity",
            "other"
          ]
        },
        "label": {
          "type": "string",
          "maxLength": 80,
          "examples": [
            "Resort fee"
          ]
        },
        "percent": {
          "type": "number",
          "exclusiveMinimum": 0,
          "maximum": 100,
          "multipleOf": 0.001,
          "x-expected": "a percentage above 0 and at most 100 (e.g. 18 or 8.875)",
          "examples": [
            18
          ]
        },
        "amount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100000000,
          "description": "A fixed fee in minor units.",
          "x-expected": "an integer in minor units (e.g. 14500 for $145.00)",
          "examples": [
            14500
          ]
        },
        "included": {
          "type": "boolean",
          "description": "true when the tier's amount already includes it; false when it's added on top."
        }
      },
      "oneOf": [
        {
          "required": [
            "percent"
          ],
          "not": {
            "required": [
              "amount"
            ]
          }
        },
        {
          "required": [
            "amount"
          ],
          "not": {
            "required": [
              "percent"
            ]
          }
        }
      ],
      "x-expected": "a fee with either percent or amount (not both)",
      "examples": [
        {
          "type": "gratuity",
          "percent": 18,
          "included": false
        }
      ]
    },
    "deposit": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "percent": {
          "type": "number",
          "exclusiveMinimum": 0,
          "maximum": 100,
          "examples": [
            25
          ]
        },
        "amount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100000000,
          "description": "Money in integer minor units (cents for usd): 14500 is $145.00.",
          "x-expected": "an integer in minor units (e.g. 14500 for $145.00)",
          "examples": [
            14500
          ]
        }
      },
      "oneOf": [
        {
          "required": [
            "percent"
          ],
          "not": {
            "required": [
              "amount"
            ]
          }
        },
        {
          "required": [
            "amount"
          ],
          "not": {
            "required": [
              "percent"
            ]
          }
        }
      ],
      "x-expected": "a deposit with either percent or amount (not both)",
      "examples": [
        {
          "percent": 25
        }
      ]
    }
  },
  "examples": [
    {
      "label": "Weekday",
      "amount": 14500,
      "currency": "usd",
      "unit": "per_person",
      "min_party": 2,
      "max_party": 4,
      "days": [
        "mon",
        "tue",
        "wed",
        "thu"
      ],
      "fees": [
        {
          "type": "tax",
          "percent": 7,
          "included": false
        }
      ]
    }
  ]
}
