{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://objectsgrid.com/.well-known/objects-catalog/Enum/v1/schema.json",
  "title": "Enum",
  "description": "A named list of values of one type, e.g. the order statuses an application offers. You choose its id.",
  "x-objectsgrid-jsonLd": false,
  "type": "object",
  "required": [
    "id",
    "valueType",
    "values"
  ],
  "additionalProperties": false,
  "properties": {
    "at_type": {
      "description": "The object type",
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "Enum"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "at_id": {
      "description": "This Enum's ObjectsGrid URL, https://apis.objectsgrid.com/<path>/<id>: its JSON-LD @id, which References point to. Set by the service.",
      "type": [
        "string",
        "null"
      ],
      "format": "uri",
      "readOnly": true
    },
    "id": {
      "description": "The unique identifier for Enum, chosen by you when creating it: 1 to 50 letters, digits, - or _, starting with a letter or a digit. It cannot change, and an id once used cannot be used again.",
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,49}$"
    },
    "identifier": {
      "description": "The unique identifier for Enum. Assigned by the server.",
      "type": [
        "string",
        "null"
      ],
      "minLength": 0,
      "maxLength": 50,
      "readOnly": true
    },
    "url": {
      "description": "This Enum URL. Assigned by the server.",
      "type": [
        "string",
        "null"
      ],
      "format": "uri",
      "minLength": 1,
      "readOnly": true
    },
    "description": {
      "description": "The Enum description",
      "type": [
        "string",
        "null"
      ],
      "minLength": 0,
      "maxLength": 255
    },
    "valueType": {
      "description": "The type of every value: val is a boolean, a string, LanguageTaggedStrings (stringLocalized), an integer, a number (float) or a date-time.",
      "type": "string",
      "enum": [
        "boolean",
        "string",
        "stringLocalized",
        "integer",
        "float",
        "dateTime"
      ]
    },
    "values": {
      "description": "The Enum values",
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "required": [
          "key",
          "val"
        ],
        "additionalProperties": false,
        "properties": {
          "key": {
            "description": "The value key",
            "type": "string",
            "minLength": 1
          },
          "val": {
            "description": "The value, of the Enum valueType"
          },
          "order": {
            "description": "The value position, for display",
            "type": "integer",
            "minimum": 0
          }
        }
      }
    },
    "disabled": {
      "description": "Is this Enum disabled",
      "type": [
        "boolean",
        "null"
      ]
    },
    "tags": {
      "description": "Tags an ABAC policy can decide on. A name may repeat; the same name and value appear once. Every stored object has them: created empty when not sent, kept by a replacement (PUT) that does not mention them, unchanged by a patch that does not mention them, cleared by null or [].",
      "type": "array",
      "default": [],
      "uniqueItems": true,
      "maxItems": 50,
      "items": {
        "$ref": "https://objectsgrid.com/.well-known/objects-catalog/Tag/v1/schema.json"
      }
    },
    "meta": {
      "description": "System-managed metadata for the object (version, audit fields). Assigned by the server.",
      "$ref": "https://objectsgrid.com/.well-known/objects-catalog/ObjectMeta/v1/schema.json",
      "readOnly": true
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "valueType": {
            "const": "boolean"
          }
        },
        "required": [
          "valueType"
        ]
      },
      "then": {
        "properties": {
          "values": {
            "items": {
              "properties": {
                "val": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "valueType": {
            "const": "string"
          }
        },
        "required": [
          "valueType"
        ]
      },
      "then": {
        "properties": {
          "values": {
            "items": {
              "properties": {
                "val": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "valueType": {
            "const": "stringLocalized"
          }
        },
        "required": [
          "valueType"
        ]
      },
      "then": {
        "properties": {
          "values": {
            "items": {
              "properties": {
                "val": {
                  "type": "array",
                  "minItems": 1,
                  "uniqueItems": true,
                  "items": {
                    "$ref": "https://objectsgrid.com/.well-known/objects-catalog/LanguageTaggedString/v1/schema.json"
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "valueType": {
            "const": "integer"
          }
        },
        "required": [
          "valueType"
        ]
      },
      "then": {
        "properties": {
          "values": {
            "items": {
              "properties": {
                "val": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "valueType": {
            "const": "float"
          }
        },
        "required": [
          "valueType"
        ]
      },
      "then": {
        "properties": {
          "values": {
            "items": {
              "properties": {
                "val": {
                  "type": "number"
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "valueType": {
            "const": "dateTime"
          }
        },
        "required": [
          "valueType"
        ]
      },
      "then": {
        "properties": {
          "values": {
            "items": {
              "properties": {
                "val": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          }
        }
      }
    }
  ]
}
