/// <summary>
        /// Handle the event
        /// </summary>
        /// <param name="initiatorplus">The initiator process (e.g. a sickness or leave) (and its children)</param>
        /// <param name="trigger">the object that triggered this event - as task in this case</param>
        /// <returns></returns>
        public override List<WorkflowHandlerAction> Handle(WorkflowInitiatorPlus initiatorplus, object trigger)
        {
            var actions = new List<WorkflowHandlerAction>();
            var config = (SicknessWorkflowConfiguration) WorkflowConfiguration;
            //what do we want to do when a sickness is created?
            var sickness = (Sickness) initiatorplus.Initiator;
            var welfarecall = (Task) trigger; 

            //create a welfare call. If sickness is not completed. 
            if (sickness.EndOfProcess == null)
            {
                var newwelfarecall = new CreateProcessTaskActionModel
                                         {
                                             Title = "Welfare Call for {0}",
                                             AssignedRoles = new List<string> { Role.BuiltInRole.LineManager.ToString() },
                                             Description = "Call {0} to check on their progress",
                                             DueDate = (welfarecall.CompletedDate ?? DateTime.Now).AddDays(config.WelfareCallDaysInterval),
                                             TaskName = "Welfare Call",

                                         };
                actions.Add(new WorkflowHandlerAction
                                {

                                    Action = WorkflowHandlerAction.Actions.AddTask,
                                    ObjectType = "Task",
                                    NewObject = newwelfarecall.ToJson(),
                                });
            }

            return actions; 
        }
        /// <summary>
        /// Handle the event
        /// </summary>
        /// <param name="initiatorplus"></param>
        /// <param name="trigger"></param>
        /// <returns>A list of actions generated by the leave created event</returns>
        public override List<WorkflowHandlerAction> Handle(WorkflowInitiatorPlus initiatorplus, object trigger)
        {
            var actions = new List<WorkflowHandlerAction>();

            //what do we want to do when a sickness is created?
            var leave = (Leave) initiatorplus.Initiator;

            //if created by a manager, then approval is implict?
            if (!leave.Approved)
            {
                //create an approval task. 
                var approval = new CreateProcessTaskActionModel
                                   {
                                       Title = "Approve Leave",
                                       AssignedRoles = new List<string> {Role.BuiltInRole.LineManager.ToString()},
                                       Description = "Review the Leave and Approve or Reject it",
                                       DueDate = DateTime.Now, //TODO: how much time should they have?
                                       TaskName = "Leave Approval",

                                   };
                actions.Add(new WorkflowHandlerAction
                                {
                                    Action = WorkflowHandlerAction.Actions.AddTask,
                                    ObjectType = "Task",
                                    NewObject = approval.ToJson(),
                                });
            }


            return actions; 
        }
        /// <summary>
        /// handle the event
        /// </summary>
        /// <param name="initiatorplus">The initiator - a sickness in this case</param>
        /// <param name="trigger"></param>
        /// <returns>A list of actions generated by this event</returns>
        public override List<WorkflowHandlerAction> Handle(WorkflowInitiatorPlus initiatorplus, object trigger)
        {
            var actions = new List<WorkflowHandlerAction>();
            var config = (SicknessWorkflowConfiguration) WorkflowConfiguration;
            //what do we want to do when a sickness is created?
            var sickness = (Sickness) initiatorplus.Initiator; //get the Sickness object that initiated the workflow

                //RULES
                //if any welfare calls in the future, kill them. 
                var futurewelfarecalls =
                    //get all future tasks
                    (from task in initiatorplus.Children.OfType<Task>()
                     where task.Type.Name == "Welfare Call"
                           && task.CompletedDate == null
                           && task.DueDate >= sickness.EndOfProcess //sickness may have ended before today. 
                     select task);

                //add all future welfare calls
                actions.AddRange((from call in futurewelfarecalls
                                  select new WorkflowHandlerAction
                                             {
                                                 Action = WorkflowHandlerAction.Actions.DeleteTask,
                                                 ObjectType = "Welfare Call",
                                                 Property = "Id",
                                                 Value = call.Id,

                                             }));

                //add RTW interview meeting
                var rtw = new CreateProcessMeetingActionModel
                              {
                                  Title = "RTW Meeting",
                                  AssignedRoles = new List<string> { Role.BuiltInRole.LineManager.ToString() },
                                  InviteeUserIds = new List<string> {sickness.Subject.UserId},
                                  Description = "Discuss recent absence with " + sickness.Subject.FullName,
                                  DueDate =
                                      (sickness.StartOfProcess.AddDays(config.RTWMeetingDaysAfter) < DateTime.Now
                                           ? DateTime.Now
                                           : sickness.StartOfProcess.AddDays(config.RTWMeetingDaysAfter)),
                                  TaskName = "RTW Meeting",


                              };
                actions.Add(new WorkflowHandlerAction
                                {

                                    Action = WorkflowHandlerAction.Actions.AddMeeting,
                                    ObjectType = "Meeting",
                                    NewObject = rtw.ToJson(),
                                });

                return actions;
            
        }
            public override List<WorkflowHandlerAction> Handle(WorkflowInitiatorPlus initiatorplus, object trigger)
            {
                return new List<WorkflowHandlerAction>
                           {
                               new TestAction
                                   {
                                       Action = "Action", 
                                       Initiator = initiatorplus.Initiator, 
                                       Trigger = trigger,
                                       ObjectType = "Object"

                                   }
                           };
            }
        /// <summary>
        /// handle the sickness created event
        /// </summary>
        /// <param name="initiatorplus"></param>
        /// <param name="trigger">The object that triggered this event, in this case the sickness</param>
        /// <returns>A list of actions to be handled by this event</returns>
        public override List<WorkflowHandlerAction> Handle(WorkflowInitiatorPlus initiatorplus, object trigger)
        {
            var actions = new List<WorkflowHandlerAction>();

            //what do we want to do when a sickness is created?
            var sickness = (Sickness) initiatorplus.Initiator;

            var config = (SicknessWorkflowConfiguration) WorkflowConfiguration;
            if (sickness.EndOfProcess == null)
            {
                //create a welfare call task 
                var welfarecall = new CreateProcessTaskActionModel
                                      {
                                          Title = "Welfare Call for {0}",
                                          AssignedRoles = new List<string>{Role.BuiltInRole.LineManager.ToString()},
                                          Description = "Call {0} to check on their progress",
                                          DueDate =
                                              (sickness.StartOfProcess.AddDays(config.WelfareCallDaysInterval) < DateTime.Now
                                                   ? DateTime.Now
                                                   : sickness.StartOfProcess.AddDays(config.WelfareCallDaysInterval)),
                                          TaskName = "Welfare Call",

                                      };
                //add the task as a new action - in json format of course
                actions.Add(new WorkflowHandlerAction
                                {
                                    Action = WorkflowHandlerAction.Actions.AddTask, 
                                    ObjectType = "Task",
                                    NewObject = welfarecall.ToJson(), //the details of the tasks
                                });
            }


           actions.Add(new WorkflowHandlerAction
                           {
                               Action = WorkflowHandlerAction.Actions.NotifyActorsOfCreation
                           });


            return actions; 
        }
 /// <summary>
 /// Event has been triggered, do something. 
 /// This is where the definition model comes into play. 
 /// For the moment, we will concentrate on making it extendable by keeping the return simple. 
 /// Ultimately, this method should be able to:
 /// Set properties of any of the HrProcess or ProcessTasks within it. 
 /// Create new ProcessTasks (or even HRProcess?)
 /// </summary>
 /// <param name="initiatorplus">This is the process that 'owns' the Workflow and ProcessTasks</param>
 /// <param name="trigger"></param>
 public abstract List<WorkflowHandlerAction> Handle(WorkflowInitiatorPlus initiatorplus, object trigger);