using PARR.Core.Services.Shortcodes;
using PARR.Domain.Entities;
using PARR.TemplateMatcher.Services.Interfaces;
using System.Runtime.CompilerServices;

namespace PARR.TemplateMatcher.Services.Implementations;

internal class TemplateNameNormalizer : ITemplateNameNormalizer
{
    private readonly IShortcodesService shortcodesService;

    public TemplateNameNormalizer(IShortcodesService shortcodesService)
    {
        this.shortcodesService = shortcodesService;
    }


    public async Task<string> GetNormalizedTemplateNameAsync(Template template, [CallerMemberName] string? caller = null)
    {
        var callerName = caller ?? "Unknown";

        if (template.Job == null)
            throw new ArgumentNullException(nameof(template.Job));

        var rawName = await shortcodesService.ApplyShortcodesAsync(template.Job.TemplateNameMask, template, callerName);

        return rawName.ToUpper();
    }
}