{
  "id": "scheduler.json",
  "title": "scheduler API",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "$ref": "#/definitions/task",
  "links": [
    {
      "title": "Get all tasks",
      "href": "/tasklist",
      "method": "GET",
      "rel": "instances",
      "schema": {"$ref": "#/definitions/taskList"}
    },
	{
      "title": "Get tasks based on filter tasktype",
      "href": "/tasks?tasktype={tasktypeFilter}",
      "description": "Get tasks based on filter tasktype",
      "method": "GET",
      "schema": {"$ref": "#/definitions/taskList"}
    },
    {
      "title": "Create a new task",
      "description": "Creates a new Task, schema on request is #/definitions/addTask",
      "href": "/addtask",
      "method": "POST",
      "rel": "create",
      "schema": {"$ref": "#/definitions/responseObject"},
      "targetSchema ": {"$ref": "#/definitions/addTask"}
    },
	{
      "title": "Modify/Update a task",
      "description": "Modify/Update a Task, schema on request is #/definitions/updateTask",
      "href": "/updatetask",
      "method": "POST",
      "rel": "create",
      "schema": {"$ref": "#/definitions/responseObject"},
      "targetSchema": {"$ref": "#/definitions/updateTask"}
    },
    {
      "title": "Remove and add a new Task",
      "href": "/removeaddtask",
      "description": "Removes all the existing tasks with given taskType and adds a new Task, schema on request is #/definitions/updateTask",
      "method": "POST",
      "rel": "self",
      "schema": {"$ref": "#/definitions/responseObject"},
      "targetSchema" : {"$ref" : "#/definitions/updateTask"}
    },	
	{
      "title": "Delete tasks",
      "href": "/deletetask",
      "description": "Delete one or more tasks, schema on request is #/definitions/deleteTask",
      "method": "POST",
      "rel": "self",
      "schema": {"$ref": "#/definitions/responseObject"},
      "targetSchema" : {"$ref" : "#/definitions/deleteTask"}
    },
	{
      "title": "Gets task execution status history in HTML table format for a given taskId",
	  "description": "Returns task execution status history as per schema #/definitions/tasksHistoryList",
      "href": "/taskshistory/{taskId}",
      "method": "GET",
      "rel": "self",
      "schema": {"$ref": "#/definitions/tasksHistoryList"}
    },
	{
      "title": "Gets task execution status history for a given taskId",
	  "description": "Returns task execution status history as per schema #/definitions/tasksStatusList",
      "href": "/taskstatus/{taskId}",
      "method": "GET",
      "rel": "self",
      "schema": {"$ref": "#/definitions/tasksStatusList"}
    }
  ],
  "definitions": {
    "taskList": {
      "type": "array",
      "items": {"$ref":"#/definitions/task"}
    }, 
    "addTask": {
	   "description": "schema for task creation",
	   "type": "object",
       "required": ["taskType","scheduleType"],
	   "additionalProperties": true,
	   "properties": {
        "taskType": {
			"description": "Name of the Task Type",
			"type": "string"
		},
        "scheduleType": {
          "type": "integer",
          "enum": [0,1,2,3,4,5,6,7,8],
          "description": "Schedule Type: 0=Immediately, 1=Once, 2=Minutes, 3=Hourly, 4=Daily, 5=Weekly, 6=Monthly, 7=Yearly, 8=Immediately After"
        },
        "taskName": {
          "description": "User given task name",
          "type": "string"
        },
		"interval": {
          "type": "integer",
          "description": "Task execution interval. Required when scheduleType >= 2 and <=7"
        },
		"startTime": {
          "type" : ["string", "null"],
		  "description" : "Task start datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ. If not provided or null, recurent task will start now()",
		  "format" : "datetime"
        },
        "stopTime": {
          "type" : ["string", "null"],
		  "description" : "Task stop datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ. If not provided or null, recurent task will never stop",
		  "format" : "datetime"
        },
		"chainAfter": {
			"description": "Chained task ID in UUID format. Required when scheduleTyp=8(Immediately After)",
			"type": ["string", "null"]
		},
		"taskparam": {
			"description": "Task parameters as name/values in JSON object format",
			"type": ["object", "null"]
		},
	    "chainTaskGroup": {
          "type" : ["string", "null"],
		  "description" : "Chain task group name"
        }	
	  }
    },
	"updateTask": {
	  "description": "schema for task update/modify",
	  "type": "object",
      "required": ["taskID", "taskType","scheduleType"],
	  "additionalProperties": true,
	  "properties": {
        "taskType": {
			"description": "Name of the Task Type",
			"type": "string"
		},
        "scheduleType": {
          "type": "integer",
          "enum": [0,1,2,3,4,5,6,7,8],
          "description": "Schedule Type: 0=Immediately, 1=Once, 2=Minutes, 3=Hourly, 4=Daily, 5=Weekly, 6=Monthly, 7=Yearly, 8=Immediately After"
        },
        "taskName": {
          "description": "User given task name",
          "type": "string"
        },
		"interval": {
          "type": "integer",
          "description": "Task execution interval. Required when scheduleType >= 2 and <=7"
        },
		"startTime": {
          "type" : ["string", "null"],
		  "description" : "Task start datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ. If not provided or null, recurent task will start now()",
		  "format" : "datetime"
        },
        "stopTime": {
          "type" : ["string", "null"],
		  "description" : "Task stop datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ. If not provided or null, recurent task will never stop",
		  "format" : "datetime"
        },
		"chainAfter": {
			"description": "Chained task ID in UUID format. Required when scheduleTyp=8(Immediately After)",
			"type": ["string", "null"],
			"format": "uuid"
		},
		"taskparam": {
			"description": "Task parameters as name/values in JSON object format",
			"type": ["object","null"]
		},
	    "chainTaskGroup": {
          "type" : ["string","null"],
		  "description" : "Chain task group name"
        }	
	  }
    },
	"deleteTask": {
	  "description": "schema for delete task input param",
      "type": "array",
	  "minItems": 1,
	  "items": {
           "type": "string",
		   "description": "Task ID in UUID format",
		   "format": "uuid"		   
	   }
    },
	"responseObject": {
      "description": "defines a response object",
      "type": "object",
      "additionalProperties": true,
      "required": ["success"],
      "properties": {
	    "taskID": {
			"description": "Task ID in UUID format",
			"type": "string",
			"format": "uuid"
		},
		"success": {
			"description": "Respose status(true or false)",
			"type": "boolean"
		},
		"errormsg":{
			"description": "Error description when success=false",
			"type": "string"		
	   }
	}
  },
    "task": {
      "description": "defines a task",
      "type": "object",
      "additionalProperties": true,
      "required": [ "taskID","taskType","scheduleType","taskName","createTime","interval","startTime","stopTime","lastExecutionTime","lastExecutionEndTime","lastExecutionStatus","chainAfter","taskparam","lastExecutionLog","chainTaskGroup","taskSize"],
      "properties": {
	    "taskID": {
			"description": "Task ID in UUID format",
			"type": "string",
			"format": "uuid"
		},
        "taskType": {
			"description": "Name of the Task Type",
			"type": "string"
		},
        "scheduleType": {
          "type": "integer",
          "enum": [0,1,2,3,4,5,6,7,8],
          "description": "Schedule Type: 0=Immediately, 1=Once, 2=Minutes, 3=Hourly, 4=Daily, 5=Weekly, 6=Monthly, 7=Yearly, 8=Immediately After"
        },
        "taskName": {
          "description": "User given task name",
          "type": "string",
		  "default": ""
        },
		"interval": {
          "type": "integer",
          "description": "Task execution interval. Used when scheduleType >= 2 and <=7",
		  "default": 1
        },
		 "lastExecutionStatus": {
          "type": "string",
          "enum": ["Scheduled","Running","Completed"],
          "description": "Task status",
		  "default": "Scheduled"
        },
        "createTime": {
          "type" : "string",
		  "description" : "Task creation datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ",
		  "format" : "datetime"
        },
        "startTime": {
          "type" : ["string", "null"],
		  "description" : "Task start datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ",
		  "format" : "datetime"
        },
        "stopTime": {
          "type" : ["string", "null"],
		  "description" : "Task stop datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ. Null means never stop",
		  "format" : "datetime"
        },
        "lastExecutionTime": {
          "type" : ["string", "null"],
		  "description" : "Task last execution begin datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ",
		  "format" : "datetime"
        },
        "lastExecutionEndTime": {
          "type" : ["string", "null"],
		  "description" : "Task last execution end datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ",
		  "format" : "datetime"
        },
		"chainAfter": {
			"description": "Chained task ID in UUID format. Required when scheduleTyp=8(Immediately After)",
			"type": ["string", "null"],
			"format": "uuid"
		},
		"taskparam": {
			"description": "Task parameters as name/values in JSON object format",
			"type": "object"
		},
        "taskSize": {
          "type": "integer",
          "description": "Number of sub-tasks",
		  "default": 1
        },
		"lastExecutionLog": {
			"description": "Task last execution log info in array of string(CSV)fomrat",
			"type": "array",
			"items": {
               "type": "string"
			 }
		},
	   "chainTaskGroup": {
          "type" : ["string", "null"],
		  "description" : "Chain task group name"
        }
      }
    },
    "tasksHistoryList": {
      "type": "array",
	  "minItems": 0,
	  "maxItems": 100,
      "items": {
	      "items": {"$ref":"#/definitions/tasksHistory"}
	  }
    },
    "tasksHistory":{
      "description": "defines a task execution status in HTML table format",
      "type": "object",
      "additionalProperties": false,
      "required": [ "header","details"],
      "properties": {
	    "header": {
			"description": "Task execution status header with start and end execution time",
			"type": "string"
		 },
		 "details": {
			"description": "Task execution details in HTML table format",
			"type": "string"
		 }
       }
	},
	"tasksStatusList": {
      "type": "array",
	  "minItems": 0,
	  "maxItems": 100,
      "items": {
	      "items": {"$ref":"#/definitions/tasksStatus"}
	  }
    },
	"tasksStatus":{
      "description": "defines a task execution status",
      "type": "object",
      "additionalProperties": false,
      "required": [ "taskid","executionbegintime","executionendtime","executionlog"],
      "properties": {
	  	 "taskid": {
			"description": "Task ID in UUID format",
			"type": "string",
			"format": "uuid"
		},
        "executionbegintime": {
          "type" : "string",
		  "description" : "Task last execution begin datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ",
		  "format" : "datetime"
        },
        "executionendtime": {
          "type" : "string",
		  "description" : "Task last execution end datetime in ISO-8601 format: YYYY-MM-DDTHH:mm:ss.sssZ",
		  "format" : "datetime"
        },
		"executionlog": {
			"description": "Task last execution log info in array of string(CSV)fomrat",
			"type": "array",
			"items": {
               "type": "string"
			 }
		}
       }
	}
}
}
