namespace StorageService.Infrastructure.Caching;

/// <summary>
/// EN: Cache key constants for Storage Service.
/// VI: Các hằng số cache key cho Storage Service.
/// </summary>
public static class CacheKeys
{
    /// <summary>
    /// EN: Cache key prefix for the service.
    /// VI: Prefix cho cache key của service.
    /// </summary>
    private const string Prefix = "storage";

    /// <summary>
    /// EN: Default cache TTL (5 minutes).
    /// VI: TTL cache mặc định (5 phút).
    /// </summary>
    public static readonly TimeSpan DefaultTtl = TimeSpan.FromMinutes(5);

    /// <summary>
    /// EN: Short cache TTL (1 minute).
    /// VI: TTL cache ngắn (1 phút).
    /// </summary>
    public static readonly TimeSpan ShortTtl = TimeSpan.FromMinutes(1);

    /// <summary>
    /// EN: Long cache TTL (30 minutes).
    /// VI: TTL cache dài (30 phút).
    /// </summary>
    public static readonly TimeSpan LongTtl = TimeSpan.FromMinutes(30);

    /// <summary>
    /// EN: Build cache key for user quota.
    /// VI: Xây dựng cache key cho user quota.
    /// </summary>
    /// <param name="userId">User ID</param>
    /// <returns>Cache key / Cache key</returns>
    public static string UserQuota(Guid userId) => $"{Prefix}:quota:{userId}";

    /// <summary>
    /// EN: Build cache key for file metadata.
    /// VI: Xây dựng cache key cho file metadata.
    /// </summary>
    /// <param name="fileId">File ID</param>
    /// <returns>Cache key / Cache key</returns>
    public static string FileMetadata(Guid fileId) => $"{Prefix}:file:{fileId}";

    /// <summary>
    /// EN: Build cache key for user's file list.
    /// VI: Xây dựng cache key cho danh sách file của user.
    /// </summary>
    /// <param name="userId">User ID</param>
    /// <param name="folderId">Folder ID (optional) / Folder ID (tùy chọn)</param>
    /// <returns>Cache key / Cache key</returns>
    public static string UserFileList(Guid userId, Guid? folderId = null) =>
        folderId.HasValue
            ? $"{Prefix}:files:{userId}:folder:{folderId}"
            : $"{Prefix}:files:{userId}:root";

    /// <summary>
    /// EN: Build pattern for invalidating all user's file cache.
    /// VI: Xây dựng pattern để invalidate tất cả cache file của user.
    /// </summary>
    /// <param name="userId">User ID</param>
    /// <returns>Cache pattern / Cache pattern</returns>
    public static string UserFilesPattern(Guid userId) => $"{Prefix}:files:{userId}:*";

    /// <summary>
    /// EN: Build cache key for folder metadata.
    /// VI: Xây dựng cache key cho folder metadata.
    /// </summary>
    /// <param name="folderId">Folder ID</param>
    /// <returns>Cache key / Cache key</returns>
    public static string FolderMetadata(Guid folderId) => $"{Prefix}:folder:{folderId}";

    /// <summary>
    /// EN: Build cache key for folder children (files and subfolders).
    /// VI: Xây dựng cache key cho folder children (files và subfolders).
    /// </summary>
    /// <param name="folderId">Folder ID</param>
    /// <returns>Cache key / Cache key</returns>
    public static string FolderChildren(Guid folderId) => $"{Prefix}:folder:{folderId}:children";

    /// <summary>
    /// EN: Build pattern for invalidating folder cache.
    /// VI: Xây dựng pattern để invalidate cache folder.
    /// </summary>
    /// <param name="folderId">Folder ID</param>
    /// <returns>Cache pattern / Cache pattern</returns>
    public static string FolderPattern(Guid folderId) => $"{Prefix}:folder:{folderId}:*";

    /// <summary>
    /// EN: Build cache key for multipart upload session.
    /// VI: Xây dựng cache key cho multipart upload session.
    /// </summary>
    /// <param name="uploadId">Upload ID</param>
    /// <returns>Cache key / Cache key</returns>
    public static string MultipartUpload(string uploadId) => $"{Prefix}:multipart:{uploadId}";
}
