{
    "$schema"               : "http://json-schema.org/draft-04/schema#",
    "id"                    : "http://schemas.elite-markets.net/eddn/commodity/3#",
    "type"                  : "object",
    "additionalProperties"  : false,
    "required": [ "$schemaRef", "header", "message" ],
    "properties": {
        "$schemaRef": {
            "type"                  : "string"
        },
        "header": {
            "type"                  : "object",
            "additionalProperties"  : true,
            "required"              : [ "uploaderID", "softwareName", "softwareVersion" ],
            "properties"            : {
                "uploaderID": {
                    "type"          : "string"
                },
                "softwareName": {
                    "type"          : "string"
                },
                "softwareVersion": {
                    "type"          : "string"
                },
                "gatewayTimestamp": {
                    "type"          : "string",
                    "format"        : "date-time",
                    "description"   : "Timestamp upon receipt at the gateway. If present, this property will be overwritten by the gateway; submitters are not intended to populate this property."
                }
            }
        },
        "message": {
            "type"                  : "object",
            "additionalProperties"  : false,
            "required"              : [ "system", "station", "timestamp", "commodities" ],
            "properties" : {
                "system" : {
                    "$ref"          : "#/definitions/systemWithId"
                },
                "station" : {
                    "$ref"          : "#/definitions/nameWithId"
                },
                "timestamp": {
                    "type"      : "string",
                    "format"    : "date-time"
                },
                "commodities": {
                    "type"      : "array",
                    "minItems"  : 1,
                    "items"     : {
                        "oneOf" : [
                            {
                                "type"                  : "object",
                                "additionalProperties"  : false,
                                "required"              : [ "name", "buyPrice", "supply", "sellPrice", "demand" ],
                                "properties"            : {
                                    "name": {
                                        "type"          :"string",
                                        "minLength"     :1
                                    },
                                    "id": {
                                        "type"        : "integer",
                                        "description" : "If present should be treated by clients as taking precedence over \"name\""
                                    },
                                    "buyPrice": {
                                        "type"          :"integer",
                                        "description"   :"Price to buy from the market"
                                    },
                                    "supply": {
                                        "type"          : "integer"
                                    },
                                    "supplyLevel": {
                                        "$ref"          : "#/definitions/levelType"
                                    },
                                    "sellPrice": {
                                        "type"          : "integer",
                                        "description"   : "Price to sell to the market"
                                    },
                                    "demand":{
                                        "type":"integer"
                                    },
                                    "demandLevel":{
                                        "$ref":"#/definitions/levelType"
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        }
    },
    "definitions": {
        "systemWithId" : {
            "type" :"object",
            "additionalProperties" : false,
            "required" : [ "name" ],
            "properties" : {
                "name"    : { "type": "string", "minLength" : 1 },
                "id"      : { "type": "integer", "description"  : "If present should be treated by clients as taking precedence over \"name\"" },
                "address" : { "type": "integer" }
            }
        },
        "nameWithId" : {
            "type" :"object",
            "additionalProperties" : false,
            "required" : [ "name" ],
            "properties" : {
                "name"    : { "type": "string", "minLength" : 1 },
                "id"      : { "type": "integer", "description"  : "If present should be treated by clients as taking precedence over \"name\"" }
            }
        }
    }
}