using IWS5.Core.Enums;
using IWS5.Core.EventTrigger;
using IWS5.Core.Models.TriggerAction;
using IWS5.DatabaseAccess.Interfaces;
using Newtonsoft.Json;

namespace IWS5.Services.EventTrigger;

public class MoveToProcessTriggerProcessor(IWorkItemReferenceRepository workItemReferenceRepository) : ITriggerProcessor
{
    public async Task<bool> ProcessTrigger(string triggerAction, int workItemId)
    {
        var triggerActionModel = JsonConvert.DeserializeObject<MoveToProcessTriggerAction>(triggerAction);
        
        var rowsAffected= await workItemReferenceRepository
            .UpdateEventId(workItemId, ATEventType.Start,  triggerActionModel.ProcessId);
        
        return rowsAffected;
    }
}