namespace Books.Api.Infrastructure.FileStorage;
///
/// Service for storing and retrieving attachment files.
/// Abstraction allows switching between local storage and cloud blob storage.
///
public interface IFileStorageService
{
///
/// Store a file and return the storage path.
///
/// Company ID for organizing files
/// Original filename
/// MIME type
/// File content stream
/// Cancellation token
/// Storage path for the file
Task StoreAsync(
string companyId,
string fileName,
string contentType,
Stream content,
CancellationToken cancellationToken = default);
///
/// Retrieve a file by its storage path.
///
/// Storage path returned from StoreAsync
/// Cancellation token
/// File content and metadata
Task GetAsync(string storagePath, CancellationToken cancellationToken = default);
///
/// Delete a file from storage.
///
/// Storage path to delete
/// Cancellation token
Task DeleteAsync(string storagePath, CancellationToken cancellationToken = default);
///
/// Get a URL for downloading/viewing a file.
/// May return a signed URL with expiration for cloud storage.
///
/// Storage path
/// URL expiration time
/// Download URL
string GetDownloadUrl(string storagePath, TimeSpan? expiresIn = null);
///
/// Gets the base storage path for canonical path validation.
///
string GetBasePath();
}
public record StorageResult
{
public required string StoragePath { get; init; }
public required string StoredFileName { get; init; }
public required long FileSize { get; init; }
}
public record FileResult
{
public required Stream Content { get; init; }
public required string ContentType { get; init; }
public required string FileName { get; init; }
public required long FileSize { get; init; }
}