{
  "$id": "https://guaix.fis.ucm.es/numina/component-schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Component",
  "description": "Describe numina component files",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "type": {
      "type": "string",
      "enum": [
        "component",
        "properties",
        "instrument",
        "setup"
      ]
    },
    "uuid": {
      "$ref": "#/definitions/uuid"
    },
    "date_start": {
     "anyOf": [
        {
          "$ref": "#/definitions/datetime"
        },
        {
          "type": "null"
        }
      ]
    },
    "date_end": {
      "anyOf": [
        {
          "$ref": "#/definitions/datetime"
        },
        {
          "type": "null"
        }
      ]
    },
    "properties": {
      "type": "array",
      "items": {
        "anyOf": [
          {
            "$ref": "#/definitions/by_name"
          },
          {
            "$ref": "#/definitions/by_uuid"
          },
          {
            "$ref": "#/definitions/config"
          }
        ]
      }
    },
    "components": {
      "type": "array",
      "items": {
        "anyOf": [
          {
            "$ref": "#/definitions/by_name"
          },
          {
            "$ref": "#/definitions/by_uuid"
          }
        ]
      }
    },
    "setup": {
      "type": "array",
      "items": {
        "anyOf": [
          {
            "$ref": "#/definitions/by_name"
          },
          {
            "$ref": "#/definitions/by_uuid"
          }
        ]
      }
    }
  },
  "required": [
    "name",
    "description",
    "uuid",
    "type",
    "date_end",
    "date_start"
  ],
  "definitions": {
    "uuid": {
      "type": "string",
      "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
    },
    "datetime": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,4})?$"
    },
    "config": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "depends": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "values": {}
      },
      "required": [
        "id",
        "depends",
        "values"
      ]
    },
    "by_name": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "id": {
          "type": "string"
        }
      },
      "required": [
        "name"
      ]
    },
    "by_uuid": {
      "type": "object",
      "properties": {
        "uuid": {
          "$ref": "#/definitions/uuid"
        },
        "id": {
          "type": "string"
        }
      },
      "required": [
        "uuid"
      ]
    }
  }
}
