using MediatR;

namespace StorageService.API.Application.Queries.Admin;

/// <summary>
/// EN: Query to get all users' quotas with pagination (Admin only).
/// VI: Query lấy quota của tất cả users với phân trang (chỉ Admin).
/// </summary>
public record GetAllUsersQuotaQuery(
    int PageNumber = 1,
    int PageSize = 20,
    string? QuotaTier = null,
    double? MinUsagePercentage = null,
    string? SortBy = null,
    bool Descending = false
) : IRequest<AllUsersQuotaResult>;

/// <summary>
/// EN: Result for all users quota query.
/// VI: Kết quả query quota tất cả users.
/// </summary>
public record AllUsersQuotaResult(
    IReadOnlyList<AdminQuotaDto> Items,
    int TotalCount,
    int PageNumber,
    int PageSize,
    int TotalPages);

/// <summary>
/// EN: DTO for quota with extended admin info.
/// VI: DTO quota với thông tin admin mở rộng.
/// </summary>
public record AdminQuotaDto(
    Guid Id,
    string UserId,
    long MaxStorageBytes,
    long UsedStorageBytes,
    long RemainingStorageBytes,
    int MaxFileCount,
    int CurrentFileCount,
    int RemainingFileCount,
    double UsagePercentage,
    string? QuotaTier,
    DateTime LastUpdatedAt,
    DateTime CreatedAt);

/// <summary>
/// EN: Query to get storage statistics (Admin only).
/// VI: Query lấy thống kê storage (chỉ Admin).
/// </summary>
public record GetStorageStatisticsQuery() : IRequest<StorageStatisticsDto>;

/// <summary>
/// EN: DTO for storage statistics.
/// VI: DTO cho thống kê storage.
/// </summary>
public record StorageStatisticsDto(
    long TotalUsers,
    long TotalStorageUsedBytes,
    long TotalStorageAllocatedBytes,
    long TotalFileCount,
    double AverageUsagePercentage,
    Dictionary<string, int> UsersByTier,
    int UsersNearLimit,
    int UsersOverLimit);

/// <summary>
/// EN: Query to get all files (Admin only).
/// VI: Query lấy tất cả files (chỉ Admin).
/// </summary>
public record AdminGetFilesQuery(
    int PageNumber = 1,
    int PageSize = 20,
    string? UserId = null,
    string? AccessLevel = null,
    string? ContentType = null,
    DateTime? UploadedAfter = null,
    DateTime? UploadedBefore = null,
    string? SortBy = null,
    bool Descending = false
) : IRequest<AdminFilesResult>;

/// <summary>
/// EN: Result for admin files query.
/// VI: Kết quả query files cho admin.
/// </summary>
public record AdminFilesResult(
    IReadOnlyList<AdminFileDto> Items,
    int TotalCount,
    int PageNumber,
    int PageSize,
    int TotalPages);

/// <summary>
/// EN: DTO for file with admin info.
/// VI: DTO file với thông tin cho admin.
/// </summary>
public record AdminFileDto(
    Guid Id,
    string UserId,
    string FileName,
    string ContentType,
    long FileSizeBytes,
    string Provider,
    string AccessLevel,
    string? FolderId,
    DateTime UploadedAt,
    DateTime? LastAccessedAt,
    bool IsDeleted);

/// <summary>
/// EN: Query to get all file shares (Admin only).
/// VI: Query lấy tất cả file shares (chỉ Admin).
/// </summary>
public record AdminGetSharesQuery(
    int PageNumber = 1,
    int PageSize = 20,
    string? Status = null,
    string? SharedBy = null
) : IRequest<AdminSharesResult>;

/// <summary>
/// EN: Result for admin shares query.
/// VI: Kết quả query shares cho admin.
/// </summary>
public record AdminSharesResult(
    IReadOnlyList<AdminShareDto> Items,
    int TotalCount,
    int PageNumber,
    int PageSize,
    int TotalPages);

/// <summary>
/// EN: DTO for share with admin info.
/// VI: DTO share với thông tin cho admin.
/// </summary>
public record AdminShareDto(
    Guid Id,
    Guid FileId,
    string SharedBy,
    string? SharedWith,
    string Permission,
    string Status,
    int DownloadCount,
    int? MaxDownloads,
    DateTime? ExpiresAt,
    DateTime CreatedAt,
    DateTime? RevokedAt);
