using MediatR;
using StorageService.Domain.AggregatesModel.FileAggregate;
namespace StorageService.API.Application.Commands;
///
/// EN: Command to request a pre-signed URL for direct upload.
/// VI: Command để yêu cầu pre-signed URL cho upload trực tiếp.
///
///
/// EN: This enables Direct Client Upload pattern where files are uploaded directly to MinIO,
/// bypassing the backend to handle millions of concurrent uploads efficiently.
/// VI: Pattern này cho phép upload trực tiếp lên MinIO, bỏ qua backend để xử lý
/// hàng triệu uploads đồng thời một cách hiệu quả.
///
/// EN: User ID requesting upload / VI: ID người dùng yêu cầu upload
/// EN: Original file name / VI: Tên file gốc
/// EN: MIME content type / VI: Content type MIME
/// EN: File size in bytes for quota check / VI: Kích thước file (bytes) để kiểm tra quota
/// EN: Access level: Public, Private, or Shared / VI: Mức truy cập: Public, Private, hoặc Shared
/// EN: Optional tenant ID / VI: Tenant ID (tùy chọn)
public record SignUploadCommand(
string UserId,
string FileName,
string ContentType,
long FileSizeBytes,
FileAccessLevel AccessLevel = FileAccessLevel.Private,
string? TenantId = null
) : IRequest;
///
/// EN: Result of sign upload request containing pre-signed URL.
/// VI: Kết quả yêu cầu sign upload chứa pre-signed URL.
///
/// EN: Whether the request was successful / VI: Yêu cầu có thành công không
/// EN: Pre-signed URL for PUT request / VI: Pre-signed URL cho PUT request
/// EN: Object key in storage / VI: Object key trong storage
/// EN: URL expiration time / VI: Thời gian hết hạn URL
/// EN: Error message if failed / VI: Thông báo lỗi nếu thất bại
public record SignUploadResult(
bool Success,
string? UploadUrl,
string? ObjectKey,
DateTime? ExpiresAt,
string? Error
)
{
///
/// EN: Create a successful result.
/// VI: Tạo kết quả thành công.
///
public static SignUploadResult Ok(string uploadUrl, string objectKey, DateTime expiresAt) =>
new(true, uploadUrl, objectKey, expiresAt, null);
///
/// EN: Create a failed result.
/// VI: Tạo kết quả thất bại.
///
public static SignUploadResult Fail(string error) =>
new(false, null, null, null, error);
}