{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "fit-tmf646.schema.json",
  "title": "Appointment Management Object",
  "oneOf": [
    { "$ref": "#/$defs/Appointment_FVO" },
    { "$ref": "#/$defs/Appointment" },
    { "$ref": "#/$defs/SearchTimeSlot_FVO" },
    { "$ref": "#/$defs/SearchTimeSlot" },
    { "$ref": "#/$defs/AppointmentCreateEvent" },
    { "$ref": "#/$defs/AppointmentAttributeValueChangeEvent" },
    { "$ref": "#/$defs/AppointmentStateChangeEvent" },
    { "$ref": "#/$defs/AppointmentDeleteEvent" },
    { "$ref": "#/$defs/SearchTimeSlotAttributeValueChangeEvent" },
    { "$ref": "#/$defs/SearchTimeSlotStateChangeEvent" }
  ],
  "$defs": {
    "Appointment_FVO": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Entity_FVO" },
        {
          "type": "object",
          "required": ["validFor"],
          "not": { "required": ["event"] },
          "properties": {
            "@type": { "const": "Appointment_FVO" },
            "category": {
              "type": "string",
              "description": "Business category"
            },
            "description": {
              "type": "string",
              "description": "Short free text describing the appointment"
            },
            "externalId": { "type": "string" },
            "externalIdentifier": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/ExternalIdentifier"
              }
            },
            "attachment": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/AttachmentRefOrValue"
              }
            },
            "note": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/Note"
              }
            },
            "relatedEntity": {
              "type": "array",
              "items": { "$ref": "#/$defs/AppointmentRelatedEntityRefOrValue" }
            },
            "validFor": {
              "$ref": "fit-common.schema.json#/$defs/TimePeriod"
            }
          }
        }
      ]
    },
    "Appointment": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Entity" },
        {
          "type": "object",
          "required": ["id", "validFor"],
          "not": { "required": ["event"] },
          "properties": {
            "@type": { "const": "Appointment" },
            "category": {
              "type": "string",
              "description": "Business category"
            },
            "creationDate": { "type": "string", "format": "date-time" },
            "description": { "type": "string" },
            "externalId": { "type": "string" },
            "externalIdentifier": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/ExternalIdentifier"
              }
            },
            "lastUpdate": { "type": "string", "format": "date-time" },
            "attachment": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/AttachmentRefOrValue"
              }
            },
            "note": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/Note"
              }
            },
            "relatedEntity": {
              "type": "array",
              "items": { "$ref": "#/$defs/AppointmentRelatedEntityRefOrValue" }
            },
            "status": { "$ref": "#/$defs/AppointmentStatusType" },
            "validFor": {
              "$ref": "fit-common.schema.json#/$defs/TimePeriod"
            }
          }
        }
      ]
    },
    "AppointmentStatusType": {
      "type": "string",
      "enum": ["initialized", "confirmed", "cancelled", "completed", "failed"]
    },
    "AppointmentRelatedEntityRefOrValue": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Extensible" },
        {
          "type": "object",
          "required": ["role", "entity"],
          "properties": {
            "role": { "type": "string" },
            "entity": { "$ref": "#/$defs/AppointmentEntityRefOrValue" }
          }
        }
      ]
    },
    "AppointmentEntityRefOrValue": {
      "oneOf": [
        { "$ref": "fit-common.schema.json#/$defs/Agreement" },
        { "$ref": "#/$defs/ProductRef" },
        { "$ref": "#/$defs/TroubleTicketRef" },
        { "$ref": "#/$defs/SearchTimeslotRef" },
        { "$ref": "#/$defs/AvailableTimeslotRef" },
        { "$ref": "#/$defs/ProductOrderRef" }
      ]
    },
    "SearchTimeSlot_FVO": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Entity_FVO" },
        {
          "type": "object",
          "not": { "required": ["event"] },
          "properties": {
            "@type": { "const": "SearchTimeSlot_FVO" },
            "appointmentCategory": { "type": "string" },
            "externalIdentifier": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/ExternalIdentifier"
              }
            },
            "requestDate": { "type": "string", "format": "date-time" },
            "relatedEntity": {
              "type": "array",
              "items": { "$ref": "#/$defs/SearchTimeSlotRelatedEntityRefOrValue" }
            },
            "requestedTimeSlot": {
              "type": "array",
              "items": { "$ref": "fit-common.schema.json#/$defs/TimeSlot" }
            }
          }
        }
      ]
    },
    "SearchTimeSlot": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Entity" },
        {
          "type": "object",
          "required": ["id"],
          "not": { "required": ["event"] },
          "properties": {
            "@type": { "const": "SearchTimeSlot" },
            "appointmentCategory": { "type": "string" },
            "externalIdentifier": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/ExternalIdentifier"
              }
            },
            "requestDate": { "type": "string", "format": "date-time" },
            "requestPostedDate": { "type": "string", "format": "date-time" },
            "searchResult": { "type": "string" },
            "state": {
              "$ref": "fit-common.schema.json#/$defs/TaskStateType"
            },
            "stateChangeDate": { "type": "string", "format": "date-time" },
            "stateChangeMessage": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/Message"
              }
            },
            "stateChangeHistory": {
              "type": "array",
              "items": {
                "$ref": "fit-common.schema.json#/$defs/StateChange"
              }
            },
            "availableTimeSlot": {
              "type": "array",
              "items": { "$ref": "fit-common.schema.json#/$defs/TimeSlot" }
            },
            "relatedEntity": {
              "type": "array",
              "items": { "$ref": "#/$defs/SearchTimeSlotRelatedEntityRefOrValue" }
            },
            "requestedTimeSlot": {
              "type": "array",
              "items": { "$ref": "fit-common.schema.json#/$defs/TimeSlot" }
            }
          }
        }
      ]
    },
    "SearchTimeSlotRelatedEntityRefOrValue": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Extensible" },
        {
          "type": "object",
          "required": ["role", "entity"],
          "properties": {
            "role": { "type": "string" },
            "entity": { "$ref": "#/$defs/SearchTimeSlotEntityRefOrValue" }
          }
        }
      ]
    },
    "SearchTimeSlotEntityRefOrValue": {
      "oneOf": [
        { "$ref": "fit-common.schema.json#/$defs/Agreement" },
        { "$ref": "#/$defs/ProductOffering" },
        { "$ref": "#/$defs/ProductRef" },
        { "$ref": "#/$defs/TroubleTicketRef" },
        { "$ref": "#/$defs/QueryProductOfferingQualificationRef" },
        { "$ref": "#/$defs/QueryProductOfferingQualificationItemRef" },
        { "$ref": "#/$defs/ProductOrderRef" }
      ]
    },
    "SearchTimeslotRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["SearchTimeslotRef"] }
          }
        }
      ]
    },
    "AvailableTimeslotRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["AvailableTimeslotRef"] }
          }
        }
      ]
    },
    "QueryProductOfferingQualificationRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["QueryProductOfferingQualificationRef"] }
          }
        }
      ]
    },
    "QueryProductOfferingQualificationItemRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["QueryProductOfferingQualificationItemRef"] }
          }
        }
      ]
    },
    "ProductOrderRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["ProductOrderRef"] }
          }
        }
      ]
    },
    "ProductOffering": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Entity" },
        {
          "type": "object",
          "properties": {
            "description": { "type": "string" },
            "version": { "type": "string" },
            "lifecycleStatus": { "type": "string" },
            "name": { "type": "string" },
            "productSpecification": { "$ref": "#/$defs/ProductSpecificationRef" }
          }
        },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["ProductOffering"] }
          }
        }
      ]
    },
    "ProductOfferingRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["ProductOfferingRef"] }
          }
        }
      ]
    },
    "ProductSpecificationRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "version": { "type": "string" },
            "targetProductSchema": { "$ref": "#/$defs/TargetProductSchema" }
          }
        }
      ]
    },
    "TargetProductSchema": {
      "type": "object",
      "properties": {
        "@schemaLocation": { "type": "string" },
        "@type": { "type": "string" }
      },
      "required": ["@schemaLocation", "@type"]
    },
    "ProductRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["ProductRef"] }
          }
        }
      ]
    },
    "TroubleTicketRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "enum": ["TroubleTicketRef"] }
          }
        }
      ]
    },
    "AppointmentCreateEvent": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Event" },
        {
          "type": "object",
          "required": ["@type", "eventType"],
          "properties": {
            "@type": { "const": "AppointmentCreateEvent" },
            "eventType": { "const": "AppointmentCreateEvent" },
            "event": { "$ref": "#/$defs/AppointmentCreateEventPayload" }
          }
        }
      ]
    },
    "AppointmentAttributeValueChangeEvent": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Event" },
        {
          "type": "object",
          "required": ["@type", "eventType"],
          "properties": {
            "@type": { "const": "AppointmentAttributeValueChangeEvent" },
            "eventType": { "const": "AppointmentAttributeValueChangeEvent" },
            "event": { "$ref": "#/$defs/AppointmentAttributeValueChangeEventPayload" }
          }
        }
      ]
    },
    "AppointmentStateChangeEvent": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Event" },
        {
          "type": "object",
          "required": ["@type", "eventType"],
          "properties": {
            "@type": { "const": "AppointmentStateChangeEvent" },
            "eventType": { "const": "AppointmentStateChangeEvent" },
            "event": { "$ref": "#/$defs/AppointmentStateChangeEventPayload" }
          }
        }
      ]
    },
    "AppointmentDeleteEvent": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Event" },
        {
          "type": "object",
          "required": ["@type", "eventType"],
          "properties": {
            "@type": { "const": "AppointmentDeleteEvent" },
            "eventType": { "const": "AppointmentDeleteEvent" },
            "event": { "$ref": "#/$defs/AppointmentDeleteEventPayload" }
          }
        }
      ]
    },
    "SearchTimeSlotAttributeValueChangeEvent": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Event" },
        {
          "type": "object",
          "required": ["@type", "eventType"],
          "properties": {
            "@type": { "const": "SearchTimeSlotAttributeValueChangeEvent" },
            "eventType": { "const": "SearchTimeSlotAttributeValueChangeEvent" },
            "event": { "$ref": "#/$defs/SearchTimeSlotAttributeValueChangeEventPayload" }
          }
        }
      ]
    },
    "SearchTimeSlotStateChangeEvent": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Event" },
        {
          "type": "object",
          "required": ["@type", "eventType"],
          "properties": {
            "@type": { "const": "SearchTimeSlotStateChangeEvent" },
            "eventType": { "const": "SearchTimeSlotStateChangeEvent" },
            "event": { "$ref": "#/$defs/SearchTimeSlotStateChangeEventPayload" }
          }
        }
      ]
    },
    "AppointmentCreateEventPayload": {
      "type": "object",
      "properties": {
        "appointment": { "$ref": "#/$defs/Appointment" }
      }
    },
    "AppointmentAttributeValueChangeEventPayload": {
      "type": "object",
      "properties": {
        "appointment": { "$ref": "#/$defs/Appointment" }
      }
    },
    "AppointmentStateChangeEventPayload": {
      "type": "object",
      "properties": {
        "appointment": { "$ref": "#/$defs/Appointment" }
      }
    },
    "AppointmentDeleteEventPayload": {
      "type": "object",
      "properties": {
        "appointment": { "$ref": "#/$defs/Appointment" }
      }
    },
    "SearchTimeSlotAttributeValueChangeEventPayload": {
      "type": "object",
      "properties": {
        "searchTimeSlot": { "$ref": "#/$defs/SearchTimeSlot" }
      }
    },
    "SearchTimeSlotStateChangeEventPayload": {
      "type": "object",
      "properties": {
        "searchTimeSlot": { "$ref": "#/$defs/SearchTimeSlot" }
      }
    }
  }
}
