using Indotalent.Infrastructure.AutoNumberGenerator;
using Indotalent.Infrastructure.Database;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Indotalent.ConfigBackEnd.Extensions;

public static class AppDbContextExtensions
{
    public static async Task<string> GenerateAutoNumberAsync(
        this AppDbContext context,
        string entityName,
        string prefixTemplate,
        string? suffixTemplate = null,
        int paddingLength = 4,
        bool useYear = true,
        bool useMonth = false,
        CancellationToken ct = default)
    {
        var generator = context.GetService<AutoNumberGeneratorService>();

        return await generator.GenerateNextNumberAsync(
            entityName,
            prefixTemplate,
            suffixTemplate,
            paddingLength,
            useYear,
            useMonth,
            ct);
    }
}