{
  "id": "http://prog.online/OrgExportGrammar#",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "schema for an OrgElement in OrgExport",
  "oneOf": [
    { "$ref": "#/definitions/OrgIdList" },
    { "$ref": "#/definitions/OrgElement" }
  ],
  "definitions": {
    "OrgIdList" : {
      "type": "array",
      "items": { "type": "string" },
      "minItems": 1,
      "uniqueItems": true
    },
    "OrgElement": {
      "type": "object",
      "properties": {
        "orgId": { "type": "string" },
        "orgObjData": {
          "type": "object",
          "oneOf": [
            { "$ref": "#/definitions/Person" },
            { "$ref": "#/definitions/Organisation" },
            { "$ref": "#/definitions/Place" }
          ]
        }
      },
      "required": [ "orgId", "orgObjData" ],
      "additionalProperties": false
    },
    "Person": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "person" ] },
        "salutation": { "type": "string" },
        "title": { "type": "string" },
        "firstName": { "type": "string" },
        "lastName": { "type": "string" },
        "sex": { "enum": [ "m", "f" ] },
        "birthdate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "deathdate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        }
      },
      "required": [ "orgObjectType", "firstName", "lastName" ],
      "additionalProperties": true
    },
    "Organisation": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "organisation" ] },
        "name": { "type": "string" },
        "legalForm": { "type": "string" },
        "foundationDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "liquidationDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "situatedAt": { "type": "string" },
        "phoneNumbers": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/PhoneNumber"
           },
           "minItems": 1,
           "uniqueItems": true
         },
        "urls": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/URL"
           },
           "minItems": 1,
           "uniqueItems":true
         },
        "emails": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Email"
           },
           "minItems": 1,
           "uniqueItems":true
         }
      },
      "required": [ "orgObjectType", "name", "legalForm" ],
      "additionalProperties": true
    },
    "Place": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "place" ] },
        "name": { "type": "string" },
        "type": { "type": "string" },
        "capacity": { "type": "string" },
        "generalInterest": { "type": "boolean" },
        "wheelchair": { "type": "boolean" },
        "nonSmoking": { "type": "boolean" },
        "wardrobe": { "type": "boolean" },
        "address": { "$ref": "#/definitions/Address" },
        "addressStub": { "$ref": "#/definitions/AddressStub" },
        "geoTag": { "$ref": "#/definitions/GeoTag" },
        "phoneNumbers": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/PhoneNumber"
           },
           "minItems": 1,
           "uniqueItems": true
        },
        "urls": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/URL"
           },
           "minItems": 1,
           "uniqueItems":true
        },
        "emails": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Email"
           },
           "minItems": 1,
           "uniqueItems":true
        }
      },
      "required": [ "orgObjectType", "name", "type" ],
      "additionalProperties": true
    },
    "Address": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "address" ] },
        "co": { "type": "string" },
        "street": { "type": "string" },
        "streetNumber": {
            "type": "string",
            "pattern": "^[1-9]([0-9a-zA-Z-]){0,15}$"
        },
        "streetAddition": { "type": "string" },
        "postalBox": { "type": "string" },
        "zip": { "type": "string" },
        "city": { "type": "string" },
        "cityAddition": { "type": "string" },
        "country": { "type": "string" },
        "fromDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "toDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        }
      },
      "required": [ "orgObjectType", "zip", "city", "country" ],
      "additionalProperties": true
    },
    "AddressStub": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "addressStub" ] },
        "zip": { "type": "string" },
        "city": { "type": "string" },
        "country": { "type": "string" },
        "description": { "type": "string" },
        "fromDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "toDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        }
      },
      "required": [ "orgObjectType", "zip", "city", "country", "description" ],
      "additionalProperties": true
    },
    "GeoTag": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "geoTag" ] },
        "longitude": { "type": "number" },
        "latitude": { "type": "number" },
        "altitude": { "type": "number" },
        "altitudeMode": { "type": "string" },
        "fromDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "toDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        }
      },
      "required": [ "orgObjectType", "longitude", "latitude" ],
      "additionalProperties": false
    },
    "Email": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "email" ] },
        "label": { "type": "string" },
        "email": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$"
        },
        "fromDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "toDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        }
      },
      "required": [ "orgObjectType", "email" ],
      "additionalProperties": false
    },
    "PhoneNumber": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "phoneNumber" ] },
        "label": { "type": "string" },
        "type": { "enum": [ "Fax", "Mobile", "Phone" ] },
        "number": {
          "type": "string",
          "pattern": "^[0-9\\s+-]{1,256}$"
        },
        "fromDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "toDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        }
      },
      "required": [ "orgObjectType", "number", "type" ],
      "additionalProperties": false
    },
    "URL": {
      "type": "object",
      "properties": {
        "orgObjectType": { "enum": [ "url" ] },
        "label": { "type": "string" },
        "type": { "type": "string" },
        "url": {
          "type": "string",
          "pattern": "^(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\\.))+(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(/[a-zA-Z0-9\\&amp;%_\\./-~-]*)?$"
        },
        "fromDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        },
        "toDate": {
            "type": "string",
            "pattern": "^(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.([0-9]{4})$"
        }
      },
      "required": [ "orgObjectType", "url", "type" ],
      "additionalProperties": false
    }
  }
}