{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://istointents.org/schemas/0.1/intent.schema.json",
  "title": "Isto Intents Intent",
  "description": "A standing purchase intent (spec section 4).",
  "type": "object",
  "required": [
    "specVersion",
    "type",
    "id",
    "created",
    "holder",
    "category",
    "country",
    "currency",
    "language",
    "statement",
    "criteria",
    "validUntil",
    "status",
    "buyer",
    "consent",
    "visibility"
  ],
  "properties": {
    "specVersion": {
      "$ref": "common.schema.json#/$defs/version"
    },
    "type": {
      "const": "intent"
    },
    "id": {
      "$ref": "common.schema.json#/$defs/id"
    },
    "created": {
      "$ref": "common.schema.json#/$defs/timestamp"
    },
    "updated": {
      "$ref": "common.schema.json#/$defs/timestamp"
    },
    "holder": {
      "$ref": "common.schema.json#/$defs/party"
    },
    "category": {
      "$ref": "common.schema.json#/$defs/category"
    },
    "country": {
      "$ref": "common.schema.json#/$defs/country"
    },
    "currency": {
      "$ref": "common.schema.json#/$defs/currency"
    },
    "language": {
      "$ref": "common.schema.json#/$defs/language"
    },
    "statement": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1000
    },
    "parser": {
      "type": "string",
      "description": "Identifier and version of the procedure that derived criteria from the statement, if any (spec §4, rule 2)."
    },
    "criteria": {
      "type": "object",
      "required": [
        "must"
      ],
      "properties": {
        "must": {
          "type": "object",
          "minProperties": 1
        },
        "nice": {
          "type": "object"
        }
      },
      "additionalProperties": false
    },
    "area": {
      "$ref": "common.schema.json#/$defs/area"
    },
    "budget": {
      "type": "object",
      "properties": {
        "min": {
          "$ref": "common.schema.json#/$defs/amount"
        },
        "max": {
          "$ref": "common.schema.json#/$defs/amount"
        }
      },
      "additionalProperties": false
    },
    "hiddenLimit": {
      "$ref": "common.schema.json#/$defs/sealed",
      "description": "The buyer's private price cap, sealed by the holder (spec §4.2)."
    },
    "buyBy": {
      "$ref": "common.schema.json#/$defs/date"
    },
    "validUntil": {
      "$ref": "common.schema.json#/$defs/timestamp"
    },
    "status": {
      "enum": [
        "active",
        "paused",
        "fulfilled",
        "withdrawn",
        "expired"
      ]
    },
    "buyer": {
      "type": "object",
      "required": [
        "pseudonym"
      ],
      "properties": {
        "pseudonym": {
          "type": "string",
          "minLength": 8
        }
      },
      "additionalProperties": false
    },
    "consent": {
      "$ref": "common.schema.json#/$defs/id"
    },
    "visibility": {
      "enum": [
        "private",
        "aggregate",
        "pseudonymous"
      ]
    },
    "allowedSellers": {
      "type": "array",
      "items": {
        "$ref": "common.schema.json#/$defs/id"
      }
    },
    "extensions": {
      "$ref": "common.schema.json#/$defs/extensions"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "category": {
            "const": "vehicle"
          }
        }
      },
      "then": {
        "properties": {
          "criteria": {
            "properties": {
              "must": {
                "$ref": "criteria-vehicle.schema.json"
              },
              "nice": {
                "$ref": "criteria-vehicle.schema.json"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "category": {
            "const": "property"
          }
        }
      },
      "then": {
        "properties": {
          "criteria": {
            "properties": {
              "must": {
                "$ref": "criteria-property.schema.json"
              },
              "nice": {
                "$ref": "criteria-property.schema.json"
              }
            }
          }
        }
      }
    }
  ],
  "additionalProperties": false
}
