using MediatR;
using StorageService.Domain.AggregatesModel.FileShareAggregate;

namespace StorageService.API.Application.Queries;

#region DTOs

/// <summary>
/// EN: DTO for file share.
/// VI: DTO cho file share.
/// </summary>
public record FileShareDto(
    Guid Id,
    Guid FileId,
    string SharedBy,
    string? SharedWith,
    string Permission,
    string ShareToken,
    bool HasPassword,
    DateTime? ExpiresAt,
    int? MaxDownloads,
    int DownloadCount,
    string Status,
    DateTime CreatedAt);

/// <summary>
/// EN: Result of accessing a shared file.
/// VI: Kết quả truy cập file được chia sẻ.
/// </summary>
public record SharedFileAccessResult(
    bool Success,
    string? DownloadUrl,
    string? FileName,
    string? ContentType,
    long? FileSizeBytes,
    string? Error)
{
    public static SharedFileAccessResult Ok(string downloadUrl, string fileName, string contentType, long fileSizeBytes) 
        => new(true, downloadUrl, fileName, contentType, fileSizeBytes, null);
    
    public static SharedFileAccessResult Fail(string error)
        => new(false, null, null, null, null, error);
}

#endregion

#region Queries

/// <summary>
/// EN: Query to get all shares for a file.
/// VI: Query để lấy tất cả shares của một file.
/// </summary>
public record GetFileSharesQuery(Guid FileId, string UserId) : IRequest<IEnumerable<FileShareDto>>;

/// <summary>
/// EN: Query to access a shared file by token.
/// VI: Query để truy cập file được chia sẻ bằng token.
/// </summary>
public record AccessSharedFileQuery(string Token, string? Password = null) : IRequest<SharedFileAccessResult>;

#endregion
