{
  "$schema": "http://json-schema.org/draft-04/schema#",

  "title": "Common definitions",

  "uint": {
    "description": "Unsigned Integer",
    "type": "number",
    "multipleOf": 1.0,
    "minimum": 0
  },

  "uint_nonzero": {
    "description": "Unsigned Integer > 0",
    "type": "number",
    "multipleOf": 1.0,
    "minimum": 0,
    "exclusiveMinimum": true
  },

  "percentage_nonzero": {
    "allOf": [
      { "$ref": "#/uint_nonzero" },
      { "maximum": 100 }
    ]
  },

  "mbps_nonzero": {
    "allOf": [
      { "$ref": "#/uint_nonzero" },
      { "maximum": 4294967296,
        "exclusiveMaximum": true
      }
    ]
  },

  "uint_uniq_nonempty_array": {
    "description": "Non-empty array of unique Unsigned Integers",
    "type": "array",
    "items": { "$ref": "#/uint" },
    "uniqueItems": true,
    "minItems": 1,
    "maxItems": 512
  },

  "uint_uniq_array": {
    "description": "Array of unique Unsigned Integers",
    "type": "array",
    "items": { "$ref": "#/uint" },
    "uniqueItems": true,
    "maxItems": 512
  },


  "string_nonempty": {
    "type": "string",
    "minLength": 1,
    "maxLength": 64
  },

  "string_hex" : {
    "type": [ "integer", "string" ],
    "pattern": "^0x[0-9a-fA-F]{1,32}$",
    "maxLength": 34,
    "minimum": 1
  },

  "app": {
    "description": "APP definition",
    "type": "object",
    "properties": {
      "name": {
        "description": "APP's name",
        "$ref": "#string_nonempty"
      },
      "cores": {
        "description": "Cores APP is pinned to",
        "$ref": "#uint_uniq_array"
      },
      "pids": {
        "description": "PIDs of APP",
        "$ref": "#uint_uniq_nonempty_array"
      }
    },
    "required": ["pids"]
  },

  "app_api_get": {
    "allOf": [
      { "$ref": "#app" },
      { "properties": {
          "id": {
            "description": "APP ID",
            "$ref": "#uint"
          }
        },
        "required": ["id"]
      }
    ]
  },

  "app_api_post": {
    "allOf": [
      { "$ref": "#app" },
      { "properties": {
          "pool_id": {
            "description": "Destination Pool ID",
            "$ref": "#uint"
          },
          "name": {},
          "cores": {},
          "pids": {}
        },
        "additionalProperties": false
      }
    ]
  },

  "app_api_put": {
    "type": "object",
    "properties": {
      "name": {
        "description": "APP's name",
        "$ref": "#string_nonempty"
      },
      "cores": {
        "description": "Cores APP is pinned to",
        "$ref": "#uint_uniq_array"
      },
      "pids": {
        "description": "PIDs of APP",
        "$ref": "#uint_uniq_nonempty_array"
      },
      "pool_id": {
        "description": "Destination Pool ID",
        "$ref": "#uint"
      }
    },
    "additionalProperties": false,
    "anyOf": [
      { "required": ["name"] },
      { "required": ["cores"] },
      { "required": ["pids"] },
      { "required": ["pool_id"] }
    ]
  },

  "power_profile" : {
    "description": "Power profile definition",
    "type": "object",
    "properties": {
      "id": {
        "description": "Power profile ID",
        "$ref": "#uint"
      },
      "min_freq": {
        "description": "Minimum frequency in MHz",
        "$ref": "#uint"
      },
      "max_freq": {
        "description": "Maximum frequency in MHz",
        "$ref": "#uint"
      },
      "epp" : {
        "description": "Energy Performance Preference",
        "$ref": "#string_nonempty"
      },
      "name" : {
        "description": "profile name",
        "$ref": "#string_nonempty"
      }
    },
    "additionalProperties": false,
    "anyOf": [
      { "required": ["min_freq"] },
      { "required": ["max_freq"] },
      { "required": ["epp"] },
      { "required": ["name"] }
    ]
  },

  "power_profile_cfg": {
    "allOf": [
      { "$ref": "#power_profile" },
      { "properties": {
          "id": {},
          "min_freq": {},
          "max_freq": {},
          "epp" : {},
          "name" : {}
        },
        "required": ["min_freq", "max_freq", "epp", "id"],
        "additionalProperties": false
      }
    ]
  },

  "power_api_get": {
    "allOf": [
      { "$ref": "#power_profile" }
    ]
  },

  "power_api_post": {
    "allOf": [
      { "$ref": "#power_profile" },
      { "properties": {
          "min_freq": {},
          "max_freq": {},
          "epp": {},
          "name": {}
        },
        "required": ["min_freq", "max_freq", "epp"],
        "additionalProperties": false
      }
    ]
  }
}
