{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://objectsgrid.com/.well-known/objects-catalog/DiscountCode/v1/schema.json",
  "title": "DiscountCode",
  "description": "Objects Grid DiscountCode Object. A code shoppers enter at checkout, its id the code: what it gives, when it applies and how often it can be used. A Cart holding it shows the discount in its totalPrice, or why the code doesn't apply; checkout checks it again and counts the use in the same step as the Order is created. ObjectsGrid's own type: Schema.org has none.",
  "type": "object",
  "properties": {
    "at_type": {
      "description": "The object type",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "DiscountCode"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "at_id": {
      "description": "This DiscountCode's ObjectsGrid URL, https://apis.objectsgrid.com/<path>/<id>: its JSON-LD @id, which References point to. Set by the service.",
      "type": [
        "string",
        "null"
      ],
      "format": "uri",
      "readOnly": true
    },
    "id": {
      "description": "The code, chosen by you, e.g. SUMMER25: 1 to 50 letters, digits, - and _, stored in upper case. Shoppers may enter it in any case. A code is used once in an Organization Account, even after a delete.",
      "type": [
        "string",
        "null"
      ],
      "pattern": "^[A-Za-z0-9_-]{1,50}$"
    },
    "identifier": {
      "description": "The unique identifier for DiscountCode. Assigned by the server.",
      "type": [
        "string",
        "null"
      ],
      "minLength": 0,
      "maxLength": 50,
      "readOnly": true
    },
    "url": {
      "description": "This DiscountCode URL. Assigned by the server.",
      "type": [
        "string",
        "null"
      ],
      "format": "uri",
      "minLength": 1,
      "readOnly": true
    },
    "name": {
      "description": "The DiscountCode name",
      "type": "array",
      "items": {
        "$ref": "https://objectsgrid.com/.well-known/objects-catalog/LanguageTaggedString/v1/schema.json"
      },
      "minItems": 1
    },
    "description": {
      "description": "What the code is for, e.g. the campaign",
      "type": [
        "array",
        "null"
      ],
      "items": {
        "$ref": "https://objectsgrid.com/.well-known/objects-catalog/LanguageTaggedString/v1/schema.json"
      }
    },
    "percentOff": {
      "description": "The percentage taken off the eligible lines, e.g. 25",
      "type": [
        "number",
        "null"
      ],
      "minimum": 0,
      "maximum": 100
    },
    "amountOff": {
      "description": "The amount taken off the eligible lines, in priceCurrency",
      "type": [
        "number",
        "null"
      ],
      "minimum": 0
    },
    "priceCurrency": {
      "description": "The currency of amountOff",
      "anyOf": [
        {
          "$ref": "https://objectsgrid.com/.well-known/objects-catalog/CurrencyCodeEnumeration/v1/schema.json"
        },
        {
          "type": "null"
        }
      ]
    },
    "freeShipping": {
      "description": "Whether it gives free shipping, which the app applies",
      "type": [
        "boolean",
        "null"
      ]
    },
    "validFrom": {
      "description": "When it starts to apply",
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "validThrough": {
      "description": "When it stops applying",
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "minimumOrderValue": {
      "description": "The least the eligible lines must total, in the currency given",
      "anyOf": [
        {
          "$ref": "https://objectsgrid.com/.well-known/objects-catalog/MonetaryAmount/v1/schema.json"
        },
        {
          "type": "null"
        }
      ]
    },
    "eligibleOffers": {
      "description": "The Offers it applies to; all when none and no eligibleCategories",
      "x-objectsgrid-rangeIncludes": [
        "Offer"
      ],
      "type": [
        "array",
        "null"
      ],
      "maxItems": 100,
      "items": {
        "$ref": "https://objectsgrid.com/.well-known/objects-catalog/Reference/v1/schema.json"
      }
    },
    "eligibleCategories": {
      "description": "The Product categories it applies to: a line applies when its product has one of them",
      "type": [
        "array",
        "null"
      ],
      "maxItems": 50,
      "items": {
        "type": "string",
        "maxLength": 100
      }
    },
    "eligibleCustomerTags": {
      "description": "Tags of the customer's Person it requires, e.g. name tier, val gold: any one is enough",
      "type": [
        "array",
        "null"
      ],
      "maxItems": 20,
      "items": {
        "$ref": "https://objectsgrid.com/.well-known/objects-catalog/Tag/v1/schema.json"
      }
    },
    "maxUses": {
      "description": "How many checkouts can use it in all",
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0
    },
    "maxUsesPerCustomer": {
      "description": "How many checkouts of one customer can use it; a cart then needs a customer",
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0
    },
    "usesCount": {
      "description": "How many checkouts used it. Set by the service at checkout, never written.",
      "type": [
        "integer",
        "null"
      ],
      "readOnly": true
    },
    "tags": {
      "description": "Tags an ABAC policy can decide on. A name may repeat; the same name and value appear once. Every stored object has them: created empty when not sent, kept by a replacement (PUT) that does not mention them, unchanged by a patch that does not mention them, cleared by null or [].",
      "type": "array",
      "default": [],
      "uniqueItems": true,
      "maxItems": 50,
      "items": {
        "$ref": "https://objectsgrid.com/.well-known/objects-catalog/Tag/v1/schema.json"
      }
    },
    "meta": {
      "description": "System-managed metadata for the object (version, audit fields). Assigned by the server.",
      "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ObjectMeta/v1/schema.json",
      "readOnly": true
    }
  },
  "required": [
    "id",
    "name"
  ],
  "x-objectsgrid-jsonLd": false,
  "oneOf": [
    {
      "required": [
        "percentOff"
      ],
      "not": {
        "required": [
          "amountOff"
        ]
      }
    },
    {
      "required": [
        "amountOff",
        "priceCurrency"
      ],
      "not": {
        "required": [
          "percentOff"
        ]
      }
    },
    {
      "required": [
        "freeShipping"
      ],
      "not": {
        "anyOf": [
          {
            "required": [
              "percentOff"
            ]
          },
          {
            "required": [
              "amountOff"
            ]
          }
        ]
      }
    }
  ]
}
