using Meezi.Core.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Meezi.Infrastructure.ExternalServices;

public class TarazTaxService : ITarazTaxService
{
    private readonly IConfiguration _configuration;
    private readonly ILogger<TarazTaxService> _logger;

    public TarazTaxService(IConfiguration configuration, ILogger<TarazTaxService> logger)
    {
        _configuration = configuration;
        _logger = logger;
    }

    public Task<TarazSubmitResult> SubmitDailyInvoicesAsync(
        string cafeId,
        DateTime dateUtc,
        CancellationToken cancellationToken = default)
    {
        var username = _configuration["Taraz:Username"];
        if (string.IsNullOrWhiteSpace(username))
        {
            _logger.LogInformation(
                "Taraz not configured — skip submit for cafe {CafeId} date {Date}",
                cafeId,
                dateUtc.Date);
            return Task.FromResult(new TarazSubmitResult(
                true,
                "MOCK-TARAZ",
                "Taraz API not configured; submission logged only."));
        }

        _logger.LogInformation("Taraz submit queued for cafe {CafeId} on {Date}", cafeId, dateUtc.Date);
        return Task.FromResult(new TarazSubmitResult(true, null, "Submission queued."));
    }
}
