{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "JSON API",
    "type": "object",
    "properties": {
        "command": {
            "type": "object",
            "oneOf": [
                {
                    "$ref": "#/definitions/Build"
                },
                {
                    "title": "Buy",
                    "required": [
                        "buy"
                    ],
                    "properties": {
                        "buy": {
                            "$ref": "#/definitions/BuyObject"
                        }
                    }
                }
            ]
        },
        "time": {
            "type": "string"
        },
        "allChat": {
            "type": "string",
            "description": "A global chat message"
        },
        "chat": {
            "$ref": "#/definitions/Chat"
        }
    },
    "required": [
        "time"
    ],
    "definitions": {
        "Chat": {
            "type": "object",
            "properties": {
                "message": {
                    "type": "string"
                }
            },
            "required": [
                "message"
            ],
            "oneOf": [
                {
                    "$ref": "#/definitions/PrivateChat"
                },
                {
                    "$ref": "#/definitions/GroupChat"
                }
            ]
        },
        "PrivateChat": {
            "title": "Private Chat",
            "properties": {
                "target": {
                    "type": "string",
                    "description": "The recipient of the message"
                }
            }
        },
        "GroupChat": {
            "title": "Group Chat",
            "properties": {
                "channel": {
                    "type": "string",
                    "description": "The channel the message is sent to"
                }
            }
        },
        "Build": {
            "required": [
                "build"
            ],
            "properties": {
                "build": {
                    "title": "Building",
                    "type": "object",
                    "properties": {
                        "building": {
                            "type": "string",
                            "description": "The name of the building"
                        },
                        "location": {
                            "type": "string",
                            "description": "The location where the building should be placed"
                        },
                        "maxCost": {
                            "type": "integer",
                            "description": "The build command should only be applied, if the actual cost do not exceed this value."
                        },
                        "exactCost": {
                            "type": "integer",
                            "description": "The build command should only be applied, if the actual cost is exactly this value."
                        }
                    }
                }
            }
        },
        "BuyObject": {
            "oneOf": [
                {
                    "$ref": "#/definitions/Spaceship"
                },
                {
                    "$ref": "#/definitions/Acres"
                }
            ],
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "The location where the spaceship should be bought"
                },
                "maxCost": {
                    "type": "integer",
                    "description": "The buy command should only be applied, if the actual cost do not exceed this value."
                },
                "exactCost": {
                    "type": "integer",
                    "description": "The buy command should only be applied, if the actual cost is exactly this value."
                }
            }
        },
        "Spaceship": {
            "title": "Spaceship",
            "required": [
                "spaceship"
            ],
            "properties": {
                "spaceship": {
                    "type": "string",
                    "description": "The name of the spaceship"
                }
            }
        },
        "Acres": {
            "title": "Acres",
            "required": [
                "acres",
                "location"
            ],
            "properties": {
                "acres": {
                    "type": "integer",
                    "description": "The size of acres"
                }
            }
        }
    }
}