using PARR.DAL.DomainServices.Shortcodes; using PARR.DAL.DomainServices.Shortcodes.Models; using PARR.DAL.Models.Job; using PARR.TemplateMatcher.Services.Interfaces; namespace PARR.TemplateMatcher.Services.Implementations; internal class TemplateNameNormalizer : ITemplateNameNormalizer { private readonly IShortcodesService shortcodesService; public TemplateNameNormalizer(IShortcodesService shortcodesService) { this.shortcodesService = shortcodesService; } public async Task GetNormalizedTemplateNameAsync(Job job, Guid unitId, int? index = null, List? templateUnitIds = null) { var templateForShortcodes = new TemplateForShortcodes { Id = Guid.Empty, Index = (index != null) ? index + 1 : index, JobId = job.Id, UnitId = unitId, Job = new JobForShortcodes { Group = job.Group != null ? new JobGroupForShortcodes { Id = job.Group.Id, GroupingUnitFieldId = job.Group.GroupingUnitFieldId, GroupType = job.Group.GroupType != null ? new JobGroupTypeForShortcodes { Code = job.Group.GroupType.Code } : null, GroupName = job.Group.GroupName } : null, Tnk = job.Tnk != null ? new TnkForShortcodes { Name = job.Tnk.Name, ShortName = job.Tnk.ShortName ?? "" } : null, WorkName = job.WorkName, Name = job.Name }, UnitsInTemplate = templateUnitIds?.Select(id => new UnitInTemplateForShortcodes { UnitId = id }).ToList() ?? new List() }; var rawName = await shortcodesService.ApplyShortcodesAsync(job.TemplateNameMask, templateForShortcodes); return rawName.ToUpper(); } }