using StorageService.Domain.AggregatesModel.FileAggregate;

namespace StorageService.API.Application.Queries;

/// <summary>
/// EN: DTO for file information.
/// VI: DTO cho thông tin file.
/// </summary>
public record FileDto(
    Guid Id,
    string UserId,
    string FileName,
    string ContentType,
    long FileSizeBytes,
    string Provider,
    string AccessLevel,
    DateTime UploadedAt,
    DateTime? LastAccessedAt);

/// <summary>
/// EN: Result for user files query.
/// VI: Kết quả query files của user.
/// </summary>
public record UserFilesResult(
    IReadOnlyList<FileDto> Files,
    int TotalCount);

/// <summary>
/// EN: DTO for user quota.
/// VI: DTO cho quota user.
/// </summary>
public record QuotaDto(
    string UserId,
    long MaxStorageBytes,
    long UsedStorageBytes,
    long RemainingStorageBytes,
    int MaxFileCount,
    int CurrentFileCount,
    int RemainingFileCount,
    double UsagePercentage,
    string? QuotaTier);

/// <summary>
/// EN: Result for download URL query.
/// VI: Kết quả query download URL.
/// </summary>
public record DownloadUrlResult(
    bool Success,
    string? Url,
    int? ExpiresInSeconds,
    string? Error);

/// <summary>
/// EN: Mapper from domain entities to DTOs.
/// VI: Mapper từ domain entities sang DTOs.
/// </summary>
public static class FileDtoMapper
{
    public static FileDto ToDto(this StorageFile file) => new(
        file.Id,
        file.UserId,
        file.FileName,
        file.ContentType,
        file.FileSizeBytes,
        file.Provider.ToString(),
        file.AccessLevel.ToString(),
        file.UploadedAt,
        file.LastAccessedAt);
}
