{       
    "id" : "maintenance.json",
    "title" : "maintenances",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$ref" : "#/definitions/maintenanceList",
    "links" : [
	{
	    "title" : "get all maitenances",
	    "href" : "/",
	    "method" : "GET",
	    "rel" : "instances",
	    "schema" : {"$ref" : "#/definitions/maintenanceList"}
	},
	{
	    "title" : "get a given maintenance",
	    "href" : "/{maintenanceIndex}",
	    "method" : "GET",
	    "rel" : "self",
	    "schema" : {"$ref" : "#/definitions/maintenance"}
	},
        {"title" : "get SSE notification stream", "href" : "/stream","method" : "GET"},
	{
	    "title" : "create a new maintenance",
	    "description" : "Create a new maintenance, schema on request is #/definitions/createMaintenace",
	    "href" : "/",
	    "method" : "POST",
	    "rel" : "create",
            "targetSchema" : {
		"$ref" : "#/definitions/createMaintenance"
	    },
	    "schema" : {
		"$ref" : "#/definitions/maintenance"
	    }
	},
	{
	    "title" : "update a maintenance",
	    "href" : "/{maintenanceIndex}",
	    "description" : "Update an existing maintenance, schema on request is #/definitions/updateMaintenance",
	    "method" : "PUT",
	    "rel" : "self",
	     "targetSchema" : {
		"$ref" : "#/definitions/maintenance"
	     },
	    "schema" : {"$ref" : "#/definitions/updateMaintenance"}
	},
	{
	    "title" : "PATCH  a maintenance",
	    "href" : "/{maintenanceIndex}",
	    "description" : "patch a maintance using an RFC6906 patch",
	    "method" : "PUT",
	    "rel" : "self",
	    "targetSchema" : {
		 "$ref" : "#/definitions/maintenance"
	     },
	    "schema" : {"$ref" : "json-patch.json"}
	},
	{
	    "title" : "delete a maintenance",
	    "href" : "/{maintenanceIndex}",	    
	    "method" : "DELETE"
	}
    ],
    "definitions" : {
	"createMaintenance" : {           
            "description" : "Represent a single maintenance",
	    "name" : "maintenance",
            "type" : "object",            "additionalProperties" : false,
	    "required" : ["topologyIndex","topoObjectType","startTime","endTime","name", "elements"],
            "properties": {
		"topoObjectType" : {"type" : "string","enum" : ["maintenance"]},
		"topologyIndex" : { "$ref" : "topology.json#/definitions/topologyIndex"},  
                "name": {
                    "description": "Maintenance name. The name can be modified, but must be unique.",
                    "$ref" : "common.json#/definitions/maintenanceName",
                    "maxLength" : 255,
                    "minLength" : 1
                },
                "user": {
                    "description": "User creating the maintenance",
                    "$ref" : "common.json#/definitions/name",
                    "maxLength" : 255,
                    "minLength" : 1
                },
                "autocomplete" : {
                    "type" : "boolean","default" : false
                },
                "startTime" : {
                    "type" : "string",
                    "format" : "date-time"
                },
                "endTime"   : {
                    "type" : "string",
                    "format" : "date-time",
                    "description" : "The planned end time of the maintenance, if autocomplete is set to true, the NorthStar Controller will complete the maintenance at that time."
                },
                "comment": {
                    "description": "commnent",
                    "type" :"string"
                },
		"elements" : {
		    "description" : "List of elements part of this maintenance",
		    "type":"array",
                    "minItems" : 1,
		    "items" : {"$ref" : "#/definitions/maintenanceElement"}		    
		},
                "noReoptimizationOnCompletion" : {"type" : "boolean", "description" : "If set to true, the rerouted LSPs will not be optimized again after the maintenance event is ended"}

            }        
	},
        "updateMaintenance" : {           
            "description" : "Represent a single maintenance",
	    "name" : "maintenance",
            "type" : "object",            "additionalProperties" : false,
	    "required" : ["topologyIndex","topoObjectType","maintenanceIndex","startTime","endTime", "elements"],
            "properties": {
		"topoObjectType" : {"type" : "string","enum" : ["maintenance"]},
		"topologyIndex" : { "$ref" : "topology.json#/definitions/topologyIndex"},
                "maintenanceIndex": {
                    "description": "Program ID for maintenance",
                    "$ref" : "common.json#/definitions/index"                    
                },
                "user": {
                    "description": "User creating the maintenance",
                    "$ref" : "common.json#/definitions/name",
                    "maxLength" : 255,
                    "minLength" : 1
                },
                "name": {
                    "description": "Maintence name",
                    "$ref" : "common.json#/definitions/maintenanceName",
                    "maxLength" : 255,
                    "minLength" : 1
                },
                "status" : {
                    "description" : "The maintenance status. The status can be set to the desired state. A planned maintenance will start on the specified startTime, and canceled one will not start but be kept inactive. A non-active Maintenance (planned, completed or cancelled) can always be reactivated (i.e put into planned status) or deleted. Once a maintenance is in progress it can only be completed or cancel.  Non-canceled jobs can be cancelled.    .The following state transitions are allowed: graphiz file: digraph MaintenanceStates {\"planned\" -> \"planned\" [label = \"Modify planned maintenance \" ]; \"planned\" -> \"cancelled\" [label = \"Cancel maintenance\" ];\"planned\" -> \"deleted\"  [label = \"Delete maintenance\" ];\"completed\" -> \"planned\"  [label = \"Modify maintenance\" ]; \"completed\" -> \"deleted\" [label = \"Delete maintenance\" ];                    \"in progress\"->\"completed\" [label = \"Complete maintenance\" ];\"in progress\"->\"cancelled\" [label = \"Cancel maintenance\" ];\"cancelled\"->\"planned\" [label = \"Modify maintenance\" ]; \"cancelled\"->\"deleted\" [label = \"Delete maintenance\" ];}",
                    "type" : "string","enum" : [    "planned",    "completed",  "cancelled",    "deleted"],
                    "default" : "planned"
                },
                "autocomplete" : {
                    "type" : "boolean","default" : false
                },
                "startTime" : {
                    "type" : "string",
                    "format" : "date-time"
                },
                "endTime"   : {
                    "type" : "string",
                    "format" : "date-time"
                },
                "comment": {
                    "description": "commnent",
                    "type" :"string"
                },
		"elements" : {
		    "description" : "List of elements part of this maintenance",
		    "type":"array",
                    "minItems" : 1,
		    "items" : {"$ref" : "#/definitions/maintenanceElement"}		    
		},
                "noReoptimizationOnCompletion" : {"type" : "boolean", "description" : "If set to true, the rerouted LSPs will not be optimized again after the maintenance event is ended"}
            }
        },
        "maintenance" : {
            "description" : "Represent a single maintenance",
	    "name" : "maintenance",
            "type" : "object",            "additionalProperties" : false,
	    "required" : ["topologyIndex","topoObjectType","maintenanceIndex","startTime","endTime"],
            "properties": {
		"topoObjectType" : {"type" : "string","enum" : ["maintenance"]},
		"topologyIndex" : { "$ref" : "topology.json#/definitions/topologyIndex"},
                "maintenanceIndex": {
                    "description": "Program ID for maintenance",
                    "$ref" : "common.json#/definitions/index"                    
                },
                "user": {
                    "description": "User creating the maintenance",
                    "$ref" : "common.json#/definitions/name",
                    "maxLength" : 255,
                    "minLength" : 1
                },
                "name": {
                    "description": "Maintence name",
                    "$ref" : "common.json#/definitions/maintenanceName",
                    "maxLength" : 255,
                    "minLength" : 1
                },
                "status" : {
                    "description" : "The maintenance status. The status can be set to the desired state. A planned maintenance will start on the specified startTime, and canceled one will not start but be kept inactive. A non-active Maintenance (planned, completed or cancelled) can always be reactivated (i.e put into planned status) or deleted. Once a maintenance is in progress it can only be completed or cancel.  Non-canceled jobs can be cancelled.    .The following state transitions are allowed: graphiz file: digraph MaintenanceStates {\"planned\" -> \"planned\" [label = \"Modify planned maintenance \" ]; \"planned\" -> \"cancelled\" [label = \"Cancel maintenance\" ];\"planned\" -> \"deleted\"  [label = \"Delete maintenance\" ];\"completed\" -> \"planned\"  [label = \"Modify maintenance\" ]; \"completed\" -> \"deleted\" [label = \"Delete maintenance\" ];                    \"in progress\"->\"completed\" [label = \"Complete maintenance\" ];\"in progress\"->\"cancelled\" [label = \"Cancel maintenance\" ];\"cancelled\"->\"planned\" [label = \"Modify maintenance\" ]; \"cancelled\"->\"deleted\" [label = \"Delete maintenance\" ];}",
                    "type" : "string","enum" : [    "planned",    "completed",    "in progress",    "cancelled",    "deleted"],
                    "default" : "planned"
                },
                "autocomplete" : {
                    "type" : "boolean","default" : false
                },
                "startTime" : {
                    "type" : "string",
                    "format" : "date-time"
                },
                "endTime"   : {
                    "type" : "string",
                    "format" : "date-time"
                },
                "comment": {
                    "description": "commnent",
                    "type" :"string"
                },
		"elements" : {
		    "description" : "List of elements part of this maintenance",
		    "type":"array",                    
		    "items" : {"$ref" : "#/definitions/maintenanceElement"}		    
		},
                "noReoptimizationOnCompletion" : {"type" : "boolean", "description" : "If set to true, the rerouted LSPs will not be optimized again after the maintenance event is ended"}
            }
        },
        "maintenanceElementId"    : {
            "type" : "object",
	    "required" : ["id","topoObjectType"],
	    "properties": {
		"id" : {"type":"string","description":"The id of the link, node or interface, depending on the type", "minLength" : 1},
		"topoObjectType" : {"type" : "string", "enum":["node","link","facility"]}
	    }
        },
        "maintenanceElementIndex" : {
            "type" : "object",
	    "required" : ["index","topoObjectType"],
	    "properties": {
                "index" : {"description":"The index of the link, node or interface, depending on the type. If both id and index are specified, index takes precedence", "$ref" : "common.json#/definitions/index" },
		"topoObjectType" : {"type" : "string", "enum":["node","link","facility"]}
	    }
        },
	"maintenanceElement" : {
	    "anyOf" : [
                {"$ref" :"#/definitions/maintenanceElementIndex" },
                {"$ref" :"#/definitions/maintenanceElementId" }
            ] 
	},
	"maintenanceList" : {
	    "type" : "array",
	    "items" : {"$ref" : "#/definitions/maintenance"}	    
	}
    }  
}
