using System; using System.Collections.Generic; using System.Linq; using LCU.API.Collections.CollectionsApiLib.Models; using LCU.API.Collections.RepoApi.Domain.Extensions; using LCU.API.Collections.RepoApi.Domain.Processing; using LCU.API.Collections.RepoApi.Extensions; using LCU.Shared.Collections.RepoApiLib.Models; namespace LCU.API.Collections.RepoApi.Domain.AlertChecker { public class O4rNoRepoChecker : IAlertChecker { private readonly RepoType _repoType; private const string O4RStatus = "O4R"; private const string EmailDestination = "RepoManagerNoRepoCo@landmarkcu.com"; public O4rNoRepoChecker(RepoType repoType) { _repoType = repoType; } private int GetDayCount() { switch (_repoType) { case RepoType.Voluntary: return 2; case RepoType.Involuntary: return 60; case RepoType.PreSkip: return 31; default: return -1; } } private int GetRepeatDayCount() { switch (_repoType) { case RepoType.Voluntary: return 1; case RepoType.Involuntary: return 30; default: return 0; } } public bool ShouldSendRepeatedAlert(int daysInStatus, int dayCount, int repeatCount) { return ( daysInStatus > dayCount && (repeatCount > 0) && ((daysInStatus - dayCount) % repeatCount == 0) ); } public bool IsRepoAssigned(RepoAccount repoAccount) { foreach (var collateral in repoAccount.Collaterals) { if (collateral.RepoCompanySelections?.FirstOrDefault(x => x.RepoCompanyAssignmentDate != null && x.RepoType == _repoType) != null) { return true; } } return false; } public List CheckForAlert(RepoAccountProcessingSlip slip) { var daysInStatus = slip.UpdatedRepoAccount.GetDaysInStatus(O4RStatus); if (daysInStatus > 0 && slip.UpdatedRepoAccount.Status == O4RStatus) { // In order to reduce duplicate notifications, do not create a notification if no repo is assigned. // An 'action needed' item will be created for O4R No Repo if no repo is assigned. A notification is redundant. if (daysInStatus < GetDayCount() || !IsRepoAssigned(slip.UpdatedRepoAccount)) { return null; } if (daysInStatus == GetDayCount() || ShouldSendRepeatedAlert(daysInStatus, GetDayCount(), GetRepeatDayCount())) { return new List { new EventAlert() { RepoId = slip.UpdatedRepoAccount.RepoId, AccountNo = slip.UpdatedRepoAccount.AccountNo, Message = "O4R No Repo", CreatedBy = "Batch", DateAdded = DateTime.Now, EmailRecipient = _repoType == RepoType.PreSkip ? EmailDestination : null, EmailBody = _repoType == RepoType.PreSkip ? CreateEmailBody(slip.UpdatedRepoAccount) : null } }; } } return null; } private string CreateEmailBody(RepoAccount repoAccount) { var message = "PreSkip has ended, please file a Skip Claim.

"; var member = repoAccount.Borrowers?.First(b => b.OwnershipType == 6); var memberName = "Member Name: " + member?.IndividualName + "
"; var accountNo = "Account No: " + repoAccount.AccountNo + "
"; var collateral = repoAccount.Collaterals.FirstOrDefault(c => c.RepoCompanySelections?.FirstOrDefault(x => x.RepoType == _repoType) != null); var year = "Year: " + collateral.Year + "
"; var make = "Make: " + collateral.Make + "
"; var model = "Model: " + collateral.Model + "
"; var vin = "VIN: " + collateral.Vin + "
"; return string.Concat(message, memberName, accountNo, year, make, model, vin); } } }