using System; using System.Collections.Generic; using System.Linq; using LCU.API.Collections.RepoApi.Domain.Processing; using LCU.Shared.Collections.RepoApiLib.Models; namespace LCU.API.Collections.RepoApi.Domain.AlertChecker { public class StatusChangeChecker : IAlertChecker { private readonly string _watchStatus; private readonly IEnumerable _fromStatusList; private const string NoStatus = ""; public StatusChangeChecker(string watchStatus, IEnumerable fromStatusList = null) { _watchStatus = watchStatus.Trim().ToUpper(); _fromStatusList = fromStatusList; } public List CheckForAlert(RepoAccountProcessingSlip slip) { var originalStatus = slip.ExistingRepoAccount?.Status.ToUpper().Trim(); var updatedStatus = slip.UpdatedRepoAccount.Status.ToUpper().Trim(); // new account. if (originalStatus == null) { originalStatus = NoStatus; } if (updatedStatus == _watchStatus && originalStatus != _watchStatus && (_fromStatusList == null || _fromStatusList.Contains(originalStatus))) { return new List { new EventAlert() { RepoId = slip.UpdatedRepoAccount.RepoId, AccountNo = slip.UpdatedRepoAccount.AccountNo, Message = "Status Changed to " + _watchStatus, SubMessage = $"Previously {originalStatus}. I confirm that I have updated the Status to {updatedStatus} in RDN.", CreatedBy = "Batch", DateAdded = DateTime.Now } }; } return null; } } }