{
  "$id": "https://verana-labs.github.io/verifiable-trust-spec/schemas/v5/org.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "OrganizationCredential",
  "description": "Identifies a legal organization that operates one or more Verifiable Services.",
  "type": "object",
  "properties": {
    "credentialSubject": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uri",
          "maxLength": 2048
        },
        "legalName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500,
          "pattern": "^\\S+( \\S+)*$"
        },
        "logoUri": {
          "type": "string",
          "format": "uri",
          "maxLength": 4096
        },
        "logoDigestSri": {
          "type": "string",
          "maxLength": 256
        },
        "registrationAuthorityId": {
          "type": "string",
          "pattern": "^RA[0-9]{6}$",
          "not": {
            "const": "RA777777"
          }
        },
        "otherRegistrationAuthorityId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500,
          "pattern": "^\\S+( \\S+)*$"
        },
        "registrationAuthorityEntityId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500,
          "pattern": "^\\S+( \\S+)*$"
        },
        "otherRegistrations": {
          "type": "array",
          "minItems": 1,
          "maxItems": 10,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "properties": {
              "registrationAuthorityId": {
                "type": "string",
                "pattern": "^RA[0-9]{6}$",
                "not": {
                  "enum": [
                    "RA999999",
                    "RA777777"
                  ]
                }
              },
              "otherRegistrationAuthorityId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500,
                "pattern": "^\\S+( \\S+)*$"
              },
              "registrationAuthorityEntityId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500,
                "pattern": "^\\S+( \\S+)*$"
              }
            },
            "required": [
              "registrationAuthorityId",
              "registrationAuthorityEntityId"
            ],
            "if": {
              "properties": {
                "registrationAuthorityId": {
                  "const": "RA888888"
                }
              },
              "required": [
                "registrationAuthorityId"
              ]
            },
            "then": {
              "required": [
                "otherRegistrationAuthorityId"
              ]
            },
            "else": {
              "not": {
                "required": [
                  "otherRegistrationAuthorityId"
                ]
              }
            },
            "additionalProperties": false
          }
        },
        "legalJurisdiction": {
          "type": "string",
          "pattern": "^[A-Z]{2}(-[A-Z0-9]{1,3})?$"
        },
        "entityCategory": {
          "type": "string",
          "enum": [
            "GENERAL",
            "BRANCH",
            "FUND",
            "SOLE_PROPRIETOR",
            "RESIDENT_GOVERNMENT_ENTITY",
            "INTERNATIONAL_ORGANIZATION"
          ]
        },
        "entityLegalFormCode": {
          "type": "string",
          "pattern": "^[A-Z0-9]{4}$"
        },
        "otherLegalForm": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500,
          "pattern": "^\\S+( \\S+)*$"
        },
        "legalAddress": {
          "type": "object",
          "properties": {
            "firstAddressLine": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500,
              "pattern": "^\\S+( \\S+)*$"
            },
            "addressNumber": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500,
              "pattern": "^\\S+( \\S+)*$"
            },
            "addressNumberWithinBuilding": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500,
              "pattern": "^\\S+( \\S+)*$"
            },
            "mailRouting": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500,
              "pattern": "^\\S+( \\S+)*$"
            },
            "additionalAddressLine": {
              "type": "array",
              "minItems": 1,
              "maxItems": 3,
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500,
                "pattern": "^\\S+( \\S+)*$"
              }
            },
            "city": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500,
              "pattern": "^\\S+( \\S+)*$"
            },
            "region": {
              "type": "string",
              "pattern": "^[A-Z]{2}-[A-Z0-9]{1,3}$"
            },
            "country": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            },
            "postalCode": {
              "type": "string",
              "minLength": 1,
              "maxLength": 500,
              "pattern": "^\\S+( \\S+)*$"
            }
          },
          "required": [
            "firstAddressLine",
            "city",
            "country"
          ],
          "additionalProperties": false
        },
        "lei": {
          "type": "string",
          "pattern": "^[0-9A-Z]{18}[0-9]{2}$"
        },
        "onboardingSummaryDigestSri": {
          "type": "string",
          "maxLength": 256
        }
      },
      "required": [
        "id",
        "legalName",
        "logoUri",
        "logoDigestSri",
        "registrationAuthorityId",
        "legalJurisdiction",
        "legalAddress"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "registrationAuthorityId": {
                "const": "RA999999"
              }
            },
            "required": [
              "registrationAuthorityId"
            ]
          },
          "then": {
            "not": {
              "anyOf": [
                {
                  "required": [
                    "registrationAuthorityEntityId"
                  ]
                },
                {
                  "required": [
                    "otherRegistrations"
                  ]
                }
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "registrationAuthorityId": {
                "const": "RA888888"
              }
            },
            "required": [
              "registrationAuthorityId"
            ]
          },
          "then": {
            "required": [
              "otherRegistrationAuthorityId"
            ]
          },
          "else": {
            "not": {
              "required": [
                "otherRegistrationAuthorityId"
              ]
            }
          }
        },
        {
          "if": {
            "required": [
              "entityLegalFormCode"
            ]
          },
          "then": {
            "if": {
              "properties": {
                "entityLegalFormCode": {
                  "enum": [
                    "8888",
                    "9999"
                  ]
                }
              }
            },
            "then": {
              "required": [
                "otherLegalForm"
              ]
            },
            "else": {
              "not": {
                "required": [
                  "otherLegalForm"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "entityCategory": {
                "const": "BRANCH"
              }
            },
            "required": [
              "entityCategory"
            ]
          },
          "then": {
            "properties": {
              "registrationAuthorityId": {
                "not": {
                  "const": "RA999999"
                }
              }
            }
          }
        }
      ]
    }
  }
}
