using Microsoft.Extensions.Logging;

namespace JSMR.Application.Logging;

public static partial class LogEvents
{
    public static void SearchCompleted(ILogger logger, long Elapsed, int Items, int Total, int Page, int Size, object Sort, object Criteria)
    {
        logger.LogInformation(
            new EventId(1000, "SearchCompleted"),
            "Search returned {Items} items (out of {Total} total) results in {Elapsed} ms on page {Page} with Size {Size}, sorted by {@Sort}, based on the following criteria: {@Criteria}",
            Items,
            Total,
            Elapsed,
            Page,
            Size,
            Sort,
            Criteria
        );
    }

    // Search
    [LoggerMessage(EventId = 1000, Level = LogLevel.Information,
        Message = "Search started Page={Page} Size={Size} Criteria={@Criteria}")]
    public static partial void SearchStart(ILogger logger, int Page, int Size, object Criteria);

    //[LoggerMessage(EventId = 1001, Level = LogLevel.Information,
    //    Message = "Search completed in {ElapsedMs} ms, Total={Total}")]
    //public static partial void SearchComplete(ILogger logger, long ElapsedMs, int Total);

    [LoggerMessage(EventId = 1001, Level = LogLevel.Information,
       Message = "Search returned {Items} items (out of {Total} total) results in {Elapsed} ms on page {Page} with Size {Size}, sorted by {@Sort}, based on the following criteria: {@Criteria}")]
    public static partial void SearchComplete(ILogger logger, long Elapsed, int Items, int Total, int Page, int Size, object Sort, object Criteria);

    [LoggerMessage(EventId = 1002, Level = LogLevel.Warning,
        Message = "External search provider timeout after {ElapsedMs} ms")]
    public static partial void ExternalSearchTimeout(ILogger logger, long ElapsedMs);

    [LoggerMessage(EventId = 1003, Level = LogLevel.Warning,
        Message = "Slow Search Detected: Elapsed {ElapsedMs} ms (threshold {ThresholdMs} ms) Path={Path}")]
    public static partial void SlowSearchDetected(ILogger logger, long ElapsedMs, long ThresholdMs, string Path);

    [LoggerMessage(EventId = 1004, Level = LogLevel.Error,
       Message = "Very Slow Search Detected: Elapsed {ElapsedMs} ms (threshold {ThresholdMs} ms) Path={Path}")]
    public static partial void VerySlowSearchDetected(ILogger logger, long ElapsedMs, long ThresholdMs, string Path);

    // Worker scan batch
    [LoggerMessage(EventId = 2000, Level = LogLevel.Information,
        Message = "Scan batch {BatchId} started")]
    public static partial void ScanBatchStart(ILogger logger, string BatchId);

    [LoggerMessage(EventId = 2001, Level = LogLevel.Information,
        Message = "Scan batch {BatchId} completed in {ElapsedMs} ms. Processed={Processed} Failures={Failures}")]
    public static partial void ScanBatchComplete(ILogger logger, string BatchId, int Processed, int Failures, long ElapsedMs);

    [LoggerMessage(EventId = 2002, Level = LogLevel.Error,
        Message = "Scan batch {BatchId} failed")]
    public static partial void ScanBatchFailed(ILogger logger, string BatchId, Exception ex);
}