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

namespace IWS5.Services.EventTrigger;

public class MoveToEventTriggerProcessor(IWorkItemReferenceRepository workItemReferenceRepository) : ITriggerProcessor
{
    public async Task<bool> ProcessTrigger(string triggerAction, int workItemId)
    {
        var triggerActionModel = JsonConvert.DeserializeObject<MoveToEventTriggerAction>(triggerAction);

        var updateResult = await workItemReferenceRepository.UpdateEventId(workItemId, triggerActionModel.EventId);

        return updateResult;
    }
}