Files
monorepo/LCU.API.Collections.RepoApi-old/LCU.API.Collections.RepoApi/Domain/AlertChecker/AuctionVinDifferentChecker.cs
T
2026-04-20 14:47:24 -05:00

51 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
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 AuctionVinDifferentChecker : IAlertChecker
{
public List<EventAlert> CheckForAlert(RepoAccountProcessingSlip slip)
{
var newEventAlerts = new List<EventAlert>();
var repoManagerVins = slip.UpdatedRepoAccount.GetCollateralVinList();
foreach (var auctionAssignment in slip.AuctionAssignments)
{
if (auctionAssignment?.AutoIMS?.VIN != null
&& !repoManagerVins.Contains(auctionAssignment.AutoIMS.VIN.Trim().ToUpper()))
{
newEventAlerts.Add(
new EventAlert()
{
RepoId = slip.UpdatedRepoAccount.RepoId,
AccountNo = slip.UpdatedRepoAccount.AccountNo,
Message = "Auction VIN Different",
SubMessage = FormatSubMessage(auctionAssignment.AutoIMS.VIN.Trim().ToUpper(), repoManagerVins),
CreatedBy = "Batch",
DateAdded = DateTime.Now
}
);
}
}
return newEventAlerts.Count > 0 ? newEventAlerts : null;
}
private static string FormatSubMessage(string auctionAssignmentVin, IReadOnlyCollection<string> vins)
{
if (vins.Count() == 1)
{
return
$"Auction Assignment VIN: {auctionAssignmentVin} differs from RepoManager VIN: {vins.First()}";
}
var repoVins = vins.Aggregate((x, y) => x + ", " + y);
return $"Auction Assignment VIN: {auctionAssignmentVin} is not among RepoManager VINs: {repoVins}";
}
}
}