namespace StorageService.Infrastructure.Configuration;

/// <summary>
/// EN: CDN configuration settings.
/// VI: Cấu hình CDN.
/// </summary>
public class CDNSettings
{
    /// <summary>EN: Enable CDN for public files / VI: Bật CDN cho public files</summary>
    public bool Enabled { get; set; } = false;

    /// <summary>EN: CDN base URL / VI: URL gốc CDN</summary>
    public string BaseUrl { get; set; } = string.Empty;

    /// <summary>EN: Cache TTL for images (seconds) / VI: TTL cache cho images (giây)</summary>
    public int ImageCacheTtlSeconds { get; set; } = 2592000; // 30 days

    /// <summary>EN: Cache TTL for videos (seconds) / VI: TTL cache cho videos (giây)</summary>
    public int VideoCacheTtlSeconds { get; set; } = 2592000; // 30 days

    /// <summary>EN: Cache TTL for documents (seconds) / VI: TTL cache cho documents (giây)</summary>
    public int DocumentCacheTtlSeconds { get; set; } = 604800; // 7 days

    /// <summary>EN: Cache TTL for other files (seconds) / VI: TTL cache cho files khác (giây)</summary>
    public int DefaultCacheTtlSeconds { get; set; } = 86400; // 1 day

    /// <summary>
    /// EN: Get cache TTL based on content type.
    /// VI: Lấy TTL cache theo content type.
    /// </summary>
    public int GetCacheTtl(string contentType)
    {
        if (string.IsNullOrEmpty(contentType))
            return DefaultCacheTtlSeconds;

        if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
            return ImageCacheTtlSeconds;

        if (contentType.StartsWith("video/", StringComparison.OrdinalIgnoreCase))
            return VideoCacheTtlSeconds;

        if (contentType.Contains("pdf", StringComparison.OrdinalIgnoreCase) ||
            contentType.Contains("document", StringComparison.OrdinalIgnoreCase) ||
            contentType.Contains("spreadsheet", StringComparison.OrdinalIgnoreCase))
            return DocumentCacheTtlSeconds;

        return DefaultCacheTtlSeconds;
    }
}
