using EonaCat.Logger.Server.Models;

namespace EonaCat.Logger.Server.Services;

public interface ILogService
{
    Task AddLogsAsync(List<LogEntry> entries);
    Task<LogEntry?> GetLogByIdAsync(string id);
    Task<PagedResult<LogEntry>> GetLogsAsync(LogQueryParams queryParams);
    Task<Dictionary<string, object>> GetStatsAsync(string? app, string? env, bool skipCache);
    Task<bool> ValidateApiKeyAsync(string apiKey);
    Task<List<string>> GetApplicationsAsync();
    Task<List<string>> GetEnvironmentsAsync();
    Task<List<TrendPoint>> GetLogTrendAsync(int hours);
}

public class LogQueryParams
{
    public string? Search { get; set; }
    public string? Application { get; set; }
    public string? Environment { get; set; }
    public int? Level { get; set; }
    public string? Category { get; set; }
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public string? UserId { get; set; }
    public string? CorrelationId { get; set; }
    public int Page { get; set; } = 1;
    public int PageSize { get; set; } = 50;
    public string? SortBy { get; set; } = "Timestamp";
    public string? SortOrder { get; set; } = "desc";
}

public class PagedResult<T>
{
    public List<T> Items { get; set; } = new();
    public int TotalCount { get; set; }
    public int Page { get; set; }
    public int PageSize { get; set; }
    public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize);
}

public class TrendPoint
{
    public DateTime Timestamp { get; set; }
    public int Count { get; set; }
    public Dictionary<int, int> ByLevel { get; set; } = new();
}