{
  "$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": ["category", "relatedEntity", "validFor"],
          "not": { "required": ["event"] },
          "properties": {
            "@type": { "const": "Appointment_FVO" },
            "category": {
              "$ref": "#/$defs/AppointmentCategoryType",
              "description": "Business category"
            },
            "description": {
              "type": "string",
              "maxLength": 1024,
              "description": "Short free text describing the appointment"
            },
            "externalId": { "type": "string" },
            "externalIdentifier": {
              "type": "array",
              "maxItems": 1,
              "items": {
                "$ref": "#/$defs/AppointmentExternalIdentifier"
              }
            },
            "attachment": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/AppointmentAttachmentRefOrValue"
              }
            },
            "note": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/AppointmentNote"
              }
            },
            "relatedEntity": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/$defs/AppointmentRelatedEntityRefOrValue" }
            },
            "validFor": {
              "$ref": "#/$defs/RequiredTimePeriod"
            }
          }
        }
      ]
    },
    "Appointment": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Entity" },
        {
          "type": "object",
          "required": ["id", "category", "relatedEntity", "status", "validFor"],
          "not": { "required": ["event"] },
          "properties": {
            "@type": { "const": "Appointment" },
            "id": { "type": "string", "minLength": 1, "maxLength": 36 },
            "category": {
              "$ref": "#/$defs/AppointmentCategoryType",
              "description": "Business category"
            },
            "creationDate": { "type": "string", "format": "date-time" },
            "description": { "type": "string", "maxLength": 1024 },
            "externalId": { "type": "string" },
            "externalIdentifier": {
              "type": "array",
              "maxItems": 1,
              "items": {
                "$ref": "#/$defs/AppointmentExternalIdentifier"
              }
            },
            "lastUpdate": { "type": "string", "format": "date-time" },
            "attachment": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/AppointmentAttachmentRefOrValue"
              }
            },
            "note": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/AppointmentNote"
              }
            },
            "relatedEntity": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/$defs/AppointmentRelatedEntityRefOrValue" }
            },
            "status": { "$ref": "#/$defs/AppointmentStatusType" },
            "validFor": {
              "$ref": "#/$defs/RequiredTimePeriod"
            }
          }
        }
      ]
    },
    "AppointmentCategoryType": {
      "type": "string",
      "enum": ["beforeFaultTicket", "duringFaultTicket", "beforeProductOrder", "duringProductOrder"]
    },
    "AppointmentStatusType": {
      "type": "string",
      "enum": ["initialized", "confirmed", "cancelled"]
    },
    "AppointmentRelatedEntityRole": {
      "type": "string",
      "enum": [
        "affectedProduct",
        "troubleTicket",
        "searchTimeSlot",
        "availableTimeSlot",
        "buyerServiceContract",
        "ordererServiceContract",
        "singleContract",
        "productOrder"
      ]
    },
    "AppointmentRelatedEntityRefOrValue": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Extensible" },
        {
          "type": "object",
          "required": ["role", "entity"],
          "properties": {
            "role": { "$ref": "#/$defs/AppointmentRelatedEntityRole" },
            "entity": { "$ref": "#/$defs/AppointmentEntityRefOrValue" }
          }
        }
      ]
    },
    "AppointmentEntityRefOrValue": {
      "oneOf": [
        { "$ref": "#/$defs/ServiceContractAgreement" },
        { "$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",
          "required": ["appointmentCategory", "relatedEntity"],
          "not": { "required": ["event"] },
          "properties": {
            "@type": { "const": "SearchTimeSlot_FVO" },
            "appointmentCategory": { "$ref": "#/$defs/AppointmentCategoryType" },
            "externalIdentifier": {
              "type": "array",
              "maxItems": 1,
              "items": {
                "$ref": "#/$defs/SearchTimeSlotExternalIdentifier"
              }
            },
            "requestPostedDate": { "type": "string", "format": "date-time" },
            "relatedEntity": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/$defs/SearchTimeSlotRelatedEntityRefOrValue" }
            },
            "requestedTimeSlot": {
              "type": "array",
              "maxItems": 1,
              "items": { "$ref": "#/$defs/TimeSlotWithRequiredPeriod" }
            }
          }
        }
      ]
    },
    "SearchTimeSlot": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Entity" },
        {
          "type": "object",
          "required": ["id", "appointmentCategory", "relatedEntity", "state", "stateChangeDate"],
          "not": { "required": ["event"] },
          "properties": {
            "@type": { "const": "SearchTimeSlot" },
            "id": { "type": "string", "minLength": 1, "maxLength": 36 },
            "appointmentCategory": { "$ref": "#/$defs/AppointmentCategoryType" },
            "externalIdentifier": {
              "type": "array",
              "maxItems": 1,
              "items": {
                "$ref": "#/$defs/SearchTimeSlotExternalIdentifier"
              }
            },
            "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": "#/$defs/SearchTimeSlotMessage"
              }
            },
            "stateChangeHistory": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/SearchTimeSlotStateChange"
              }
            },
            "availableTimeSlot": {
              "type": "array",
              "items": { "$ref": "#/$defs/AvailableTimeSlotWithRequiredPeriod" }
            },
            "relatedEntity": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/$defs/SearchTimeSlotRelatedEntityRefOrValue" }
            },
            "requestedTimeSlot": {
              "type": "array",
              "maxItems": 1,
              "items": { "$ref": "#/$defs/TimeSlotWithRequiredPeriod" }
            }
          }
        }
      ]
    },
    "SearchTimeSlotRelatedEntityRole": {
      "type": "string",
      "enum": [
        "troubleTicket",
        "buyerServiceContract",
        "ordererServiceContract",
        "singleContract",
        "affectedProduct",
        "optionalServices",
        "affectedQualification",
        "affectedQualificationItem",
        "affectedProductOrder"
      ]
    },
    "SearchTimeSlotRelatedEntityRefOrValue": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Extensible" },
        {
          "type": "object",
          "required": ["role", "entity"],
          "properties": {
            "role": { "$ref": "#/$defs/SearchTimeSlotRelatedEntityRole" },
            "entity": { "$ref": "#/$defs/SearchTimeSlotEntityRefOrValue" }
          }
        }
      ]
    },
    "SearchTimeSlotEntityRefOrValue": {
      "oneOf": [
        { "$ref": "#/$defs/ServiceContractAgreement" },
        { "$ref": "#/$defs/ProductOffering" },
        { "$ref": "#/$defs/ProductRef" },
        { "$ref": "#/$defs/TroubleTicketRef" },
        { "$ref": "#/$defs/QueryProductOfferingQualificationRef" },
        { "$ref": "#/$defs/QueryProductOfferingQualificationItemRef" },
        { "$ref": "#/$defs/ProductOrderRef" }
      ]
    },
    "RequiredTimePeriod": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/TimePeriod" },
        {
          "type": "object",
          "required": ["startDateTime", "endDateTime"]
        }
      ]
    },
    "TimeSlotWithRequiredPeriod": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/TimeSlot" },
        {
          "type": "object",
          "properties": {
            "validFor": { "$ref": "#/$defs/RequiredTimePeriod" }
          }
        }
      ]
    },
    "AvailableTimeSlotWithRequiredPeriod": {
      "allOf": [
        { "$ref": "#/$defs/TimeSlotWithRequiredPeriod" },
        {
          "type": "object",
          "required": ["id"],
          "properties": {
            "id": { "type": "string", "minLength": 1, "maxLength": 36 }
          }
        }
      ]
    },
    "ServiceContractAgreement": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Agreement" },
        {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "enum": ["buyerServiceContract", "ordererServiceContract", "singleContract"]
            }
          }
        }
      ]
    },
    "AppointmentExternalIdentifier": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/ExternalIdentifier" },
        {
          "type": "object",
          "properties": {
            "externalIdentifierType": { "const": "appointmentExternalId" }
          }
        }
      ]
    },
    "SearchTimeSlotExternalIdentifier": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/ExternalIdentifier" },
        {
          "type": "object",
          "properties": {
            "externalIdentifierType": { "const": "SearchTimeSlotExternalId" }
          }
        }
      ]
    },
    "AppointmentAttachmentRefOrValue": {
      "oneOf": [
        { "$ref": "#/$defs/AppointmentAttachmentRef" },
        { "$ref": "#/$defs/AppointmentAttachment" }
      ]
    },
    "AppointmentAttachment": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Attachment" },
        {
          "type": "object",
          "properties": {
            "@type": { "const": "Attachment" },
            "validFor": { "$ref": "#/$defs/RequiredTimePeriod" }
          }
        }
      ]
    },
    "AppointmentAttachmentRef": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/AttachmentRef" },
        {
          "type": "object",
          "required": ["@referredType"],
          "properties": {
            "@type": { "const": "AttachmentRef" },
            "@referredType": { "const": "Attachment" }
          }
        }
      ]
    },
    "AppointmentNote": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Note" },
        {
          "type": "object",
          "properties": {
            "@type": { "type": "string", "maxLength": 40 },
            "text": { "type": "string", "maxLength": 1024 }
          }
        }
      ]
    },
    "SearchTimeSlotMessage": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/Message" },
        {
          "type": "object",
          "required": ["code", "text"],
          "properties": {
            "code": { "type": "string", "maxLength": 10 },
            "text": { "type": "string", "maxLength": 255 },
            "additionalInformation": { "type": "string", "maxLength": 255 }
          }
        }
      ]
    },
    "SearchTimeSlotStateChange": {
      "allOf": [
        { "$ref": "fit-common.schema.json#/$defs/StateChange" },
        {
          "type": "object",
          "required": ["stateChangeDate", "state", "stateChangeMessage"],
          "properties": {
            "state": {
              "$ref": "fit-common.schema.json#/$defs/TaskStateType"
            },
            "stateChangeMessage": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/$defs/SearchTimeSlotMessage" }
            }
          }
        }
      ]
    },
    "SearchTimeslotRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "required": ["@referredType"],
          "properties": {
            "@type": { "type": "string", "enum": ["SearchTimeslotRef"] },
            "@referredType": { "const": "SearchTimeslot" }
          }
        }
      ]
    },
    "AvailableTimeslotRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "required": ["@referredType"],
          "properties": {
            "@type": { "type": "string", "enum": ["AvailableTimeslotRef"] },
            "@referredType": { "const": "AvailableTimeslot" }
          }
        }
      ]
    },
    "QueryProductOfferingQualificationRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "required": ["@referredType"],
          "properties": {
            "@type": { "type": "string", "enum": ["QueryProductOfferingQualificationRef"] },
            "@referredType": { "const": "QueryProductOfferingQualification" }
          }
        }
      ]
    },
    "QueryProductOfferingQualificationItemRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "required": ["@referredType"],
          "properties": {
            "@type": { "type": "string", "enum": ["QueryProductOfferingQualificationItemRef"] },
            "@referredType": { "const": "QueryProductOfferingQualificationItem" }
          }
        }
      ]
    },
    "ProductOrderRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "required": ["@referredType"],
          "properties": {
            "@type": { "type": "string", "enum": ["ProductOrderRef"] },
            "@referredType": { "const": "ProductOrder" }
          }
        }
      ]
    },
    "ProductOffering": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/Entity" },
        {
          "type": "object",
          "required": ["name"],
          "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",
          "required": ["@referredType"],
          "properties": {
            "@type": { "type": "string", "enum": ["ProductRef"] },
            "@referredType": { "const": "Product" }
          }
        }
      ]
    },
    "TroubleTicketRef": {
      "allOf": [
        { "$ref": "fit-core.schema.json#/$defs/EntityRef" },
        {
          "type": "object",
          "required": ["@referredType"],
          "properties": {
            "@type": { "type": "string", "enum": ["TroubleTicketRef"] },
            "@referredType": { "const": "TroubleTicket" }
          }
        }
      ]
    },
    "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",
      "required": ["appointment"],
      "properties": {
        "appointment": { "$ref": "#/$defs/AppointmentCreateEventAppointment" }
      }
    },
    "AppointmentAttributeValueChangeEventPayload": {
      "type": "object",
      "required": ["appointment"],
      "properties": {
        "appointment": { "$ref": "#/$defs/Appointment" }
      }
    },
    "AppointmentStateChangeEventPayload": {
      "type": "object",
      "required": ["appointment"],
      "properties": {
        "appointment": {
          "oneOf": [
            { "$ref": "#/$defs/AppointmentConfirmedStateChangeEventAppointment" },
            { "$ref": "#/$defs/AppointmentCancelledStateChangeEventAppointment" }
          ]
        }
      }
    },
    "AppointmentDeleteEventPayload": {
      "type": "object",
      "required": ["appointment"],
      "properties": {
        "appointment": { "$ref": "#/$defs/Appointment" }
      }
    },
    "SearchTimeSlotAttributeValueChangeEventPayload": {
      "type": "object",
      "required": ["searchTimeSlot"],
      "properties": {
        "searchTimeSlot": { "$ref": "#/$defs/SearchTimeSlot" }
      }
    },
    "SearchTimeSlotStateChangeEventPayload": {
      "type": "object",
      "required": ["searchTimeSlot"],
      "properties": {
        "searchTimeSlot": {
          "oneOf": [
            { "$ref": "#/$defs/SearchTimeSlotInProgressStateChangeEventSearchTimeSlot" },
            { "$ref": "#/$defs/SearchTimeSlotDoneStateChangeEventSearchTimeSlot" },
            { "$ref": "#/$defs/SearchTimeSlotRejectedStateChangeEventSearchTimeSlot" }
          ]
        }
      }
    },
    "AppointmentCreateEventAppointment": {
      "allOf": [
        { "$ref": "#/$defs/Appointment" },
        {
          "type": "object",
          "required": ["creationDate", "status"],
          "properties": {
            "status": { "const": "initialized" }
          }
        }
      ]
    },
    "AppointmentConfirmedStateChangeEventAppointment": {
      "allOf": [
        { "$ref": "#/$defs/Appointment" },
        {
          "type": "object",
          "required": ["status"],
          "properties": {
            "status": { "const": "confirmed" }
          }
        }
      ]
    },
    "AppointmentCancelledStateChangeEventAppointment": {
      "allOf": [
        { "$ref": "#/$defs/Appointment" },
        {
          "type": "object",
          "required": ["status"],
          "properties": {
            "status": { "const": "cancelled" }
          }
        }
      ]
    },
    "SearchTimeSlotInProgressStateChangeEventSearchTimeSlot": {
      "allOf": [
        { "$ref": "#/$defs/SearchTimeSlot" },
        {
          "type": "object",
          "required": ["state"],
          "properties": {
            "state": { "const": "inProgress" }
          }
        }
      ]
    },
    "SearchTimeSlotDoneStateChangeEventSearchTimeSlot": {
      "allOf": [
        { "$ref": "#/$defs/SearchTimeSlot" },
        {
          "type": "object",
          "required": ["state"],
          "properties": {
            "state": { "const": "done" }
          }
        }
      ]
    },
    "SearchTimeSlotRejectedStateChangeEventSearchTimeSlot": {
      "allOf": [
        { "$ref": "#/$defs/SearchTimeSlot" },
        {
          "type": "object",
          "required": ["state"],
          "properties": {
            "state": { "const": "rejected" }
          }
        }
      ]
    }
  }
}
