using PARR.Core.Services.Shortcodes.Enums;
using PARR.Core.Services.Shortcodes.Models;
using System.Text.RegularExpressions;

namespace PARR.Core.Services.Shortcodes.Handlers;

internal class IndexShortcodeHandler : IShortcodeHandler
{
    public int Order => 15;

    private static readonly Regex _pattern = new(@"%ИНДЕКС%", RegexOptions.Compiled | RegexOptions.IgnoreCase);

    public Regex Pattern => _pattern;

    public ShortcodeDataRequirementsEnum Requirements => ShortcodeDataRequirementsEnum.None;

    public Task<string> ResolveAsync(string input, TemplateForShortcode template, string caller, CancellationToken ct = default)
    {
        if (template.Index.HasValue && input.Contains("%ИНДЕКС%", StringComparison.OrdinalIgnoreCase))
        {
            return Task.FromResult(input.Replace("%ИНДЕКС%", template.Index.Value.ToString(), StringComparison.OrdinalIgnoreCase));
        }
        return Task.FromResult(input);
    }
}