{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "https://schema.entrecode.de/schema-data/dm-assetgroup",
  "allOf": [
    {
      "$ref": "https://schema.entrecode.de/schema-data/hal#/definitions/halResource"
    },
    {
      "type": "object",
      "properties": {
        "assetGroupID": {
          "readonly": true,
          "description": "The unique ID of the asset group (and also the name)",
          "type": "string",
          "minLength": 1,
          "maxLength": 32,
          "pattern": "^((?!^image$|^video$|^audio$|^plain$|^document$|^spreadsheet$|^archive$)[a-z0-9_-]{1,32})$"
        },
        "public": {
          "description": "Read-only field indicating if assets in this group are generally public",
          "type": "boolean"
        },
        "settings": {
          "$ref": "#/definitions/settings"
        },
        "policies": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "method": {
                "type": "string",
                "pattern": "^get|put|post|delete$"
              },
              "user": {
                "description": "Either not authenticated (public) or a dm user (dmUser)",
                "type": "string",
                "enum": ["public", "dmUser"]
              },
              "conditions": {
                "$ref": "#/definitions/condition"
              }
            },
            "additionalProperties": false,
            "required": ["method", "user"]
          }
        },
        "_links": {
          "required": ["self", "collection", "ec:datamanager", "ec:dm-assets"]
        }
      },
      "required": ["assetGroupID", "public", "settings", "policies"]
    }
  ],
  "definitions": {
    "condition": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "properties": {
            "field": {
              "enum": [
                "assetID",
                "title",
                "type",
                "mimetype",
                "created",
                "modified",
                "creator",
                "creatorType",
                "tags",
                "file.size"
              ]
            },
            "operator": {
              "enum": ["=", "!=", "<", "<=", ">", ">=", "contains", "containsNot", "hasRole", "hasNotRole"]
            },
            "variable": {
              "enum": ["accountID", "roles", "now"]
            },
            "constant": {}
          },
          "oneOf": [
            {
              "required": ["field", "operator", "variable"]
            },
            {
              "required": ["field", "operator", "constant"]
            }
          ],
          "additionalProperties": false
        },
        {
          "type": "array",
          "items": [
            {
              "$ref": "#/definitions/condition"
            },
            {
              "type": "string",
              "pattern": "^and|or$"
            },
            {
              "$ref": "#/definitions/condition"
            }
          ],
          "additionalItems": false
        }
      ]
    },
    "settings": {
      "description": "Individual settings for this Asset Group",
      "type": "object",
      "properties": {
        "urlExpiration": {
          "description": "ISO 8601 duration determining how long URLs will be valid, if this assetgroup is non-public. Overwrites global setting from Data Manager.",
          "type": ["string", "null"],
          "pattern": "^P(?!$)(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?$"
        },
        "disabledTypes": {
          "description": "List of asset types and / or mime types that may not be used in this assetgroup",
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "string",
                "enum": ["image", "video", "audio", "plain", "document", "spreadsheet", "archive", "other"]
              },
              {
                "type": "string",
                "pattern": "^(image|video|audio|text|application)/[a-z0-9\\.+-]+$"
              }
            ]
          }
        },
        "imageSizes": {
          "description": "List of image sizes to generate for image type assets. Overwrites global setting from Data Manager.",
          "type": "array",
          "items": {
            "type": "number",
            "multipleOf": 1.0,
            "minimum": 1
          }
        },
        "thumbSizes": {
          "description": "List of thumbnail sizes to generate for assets. Overwrites global setting from Data Manager.",
          "type": "array",
          "items": {
            "type": "number",
            "multipleOf": 1.0,
            "minimum": 1
          }
        },
        "urls": {
          "type": "object",
          "properties": {
            "public": {
              "type": "string",
              "format": "uri"
            },
            "private": {
              "type": "string",
              "format": "uri"
            }
          },
          "additionalProperties": false
        },
        "preserveFilenames": {
          "type": "boolean"
        },
        "includeAssetIDInPath": {
          "type": "boolean"
        },
        "thumbMimeType": {
          "oneOf": [{ "type": "null" }, { "type": "string", "enum": ["image/jpeg"] }]
        },
        "variantMimeType": {
          "oneOf": [{ "type": "null" }, { "type": "string", "enum": ["image/jpeg"] }]
        },
        "jpegQuality": {
          "type": "integer",
          "minimum": 10,
          "maximum": 90
        },
        "autoDelete": {
          "type": "string",
          "description": "Automatically delete Assets after specified timespan. Do not set to retain assets. Note that a script is periodically running for the deletion. So a value of '1 second' will not necessarily make the deletion instant, but will delete assets on the next run of the deletion script."
        },
        "deletePermanently": {
          "type": "string",
          "description": "Timespan after which a deleted asset is physically deleted. Default is 7 days. Note that a script is periodically running for the deletion. So a value of '1 second' will not necessarily make the deletion instant, but will let deleted assets be removed on the next run of the deletion script."
        },
        "defaultVariants": {
          "type": "array",
          "items": { "type": "integer" }
        },
        "additionalVariants": {
          "type": "array",
          "items": { "type": "string", "enum": ["image/webp", "image/jpeg", "image/png"] }
        },
        "optimize": {
          "oneOf": [{ "type": "null" }, { "type": "boolean" }]
        },
        "download": {
          "type": "boolean",
          "default": false
        }
      },
      "additionalProperties": false
    }
  }
}
