{ "$schema":                  "https://json-schema.org/draft/2020-12/schema",
  "$id":                      "https://schemas.mpai.community/MMM4/V2.2/data/Licence.json",
  "title":                    "Licence V2.2",
  "type":                     "object", 
  "additionalProperties":     false,
  "required":                 [ "Header", "LicenceID", "LicensorID", "LicenseeID", "LicensorRights", "LicenseeRights", 
                                "IsFirstLicence" ], 
  "properties":               {

    "Header":                 { "type": "string", "pattern": "^MMM-LIC-V[0-9]{1,2}[.][0-9]{1,2}$" },
    "MInstanceID":            { "type": "string", "minLength": 1 },
    "MEnvironmentID":         { "type": "string" },
    "LicenceID":              { "type": "string", "minLength": 1 },
    "LicenceTime":            { "$ref": "https://schemas.mpai.community/OSD/V1.5/data/Time.json" },
    "LicenceIssuanceTime":    { "$ref": "https://schemas.mpai.community/OSD/V1.5/data/Time.json" },
    "LicenceDuration":        { "$ref": "https://schemas.mpai.community/OSD/V1.5/data/Time.json" },

    "LicensorID":             { "type": "string", "minLength": 1 },
    "LicenseeID":             { "type": "string", "minLength": 1 },
    "ServiceProviderID":      { "type": "string" },

    "LicensorRights":         { "$ref": "#/$defs/Rights" },
    "LicenseeRights":         { "$ref": "#/$defs/Rights" },

    "IsFirstLicence":         { "type": "boolean", "default": true,
                                "description": "True for the first licence built on this; subsequent licences set to false." },

    "ThirdPartyID":           { "type": "string", "enum": ["THIRD-PARTY-DUMMY"],
                                "description": "Dummy third party identifier required for non-first licences." },

    "ThirdPartyRights":       { "type": "object", "required": ["Right"], "properties": {
      "Right":                { "$ref": "https://schemas.mpai.community/MMM4/V2.2/data/Right.json" } } },

    "NewLicenseeRights":      { "type": "object", "required": ["Right"], "properties": {
      "Right":                { "$ref": "https://schemas.mpai.community/MMM4/V2.2/data/Right.json" } } },

    "DataXMData":             { "$ref": "https://schemas.mpai.community/PTF/V1.0/data/DataExchangeMetadata.json" },
    "DescrMetadata":          { "type": "string", "maxLength": 2048 } },

  "allOf": [                  { "if":   { "properties": { "IsFirstLicence": { "const": false } } },
                                "then": { "required": ["ThirdPartyID", "ThirdPartyRights", "NewLicenseeRights"] } } ],

  "$defs":                    {

    "Rights":                 { "type": "array", "minItems": 1, "items": { "oneOf": [

                              { "type": "object", "additionalProperties": false, "required": [ "Right" ], "properties": { 
      "Right":                { "$ref": "https://schemas.mpai.community/MMM4/V2.2/data/Right.json" } } },
                              { "type": "object", "additionalProperties": false, "required": [ "RightID" ], "properties": { 
      "RightID":              { "type": "string" } } } ] } } } }