using System.Text.Json.Serialization;

namespace Jellyfin.Plugin.SRFPlay.Api.Models;

// NOTE: DrmList is typed as object? because the SRF API returns either null or a JSON array.
// IsPlayable checks for both null and empty array ("[]") to determine if content is DRM-free.

/// <summary>
/// Represents a streaming resource (URL) in the SRF API response.
/// </summary>
public class Resource
{
    /// <summary>
    /// Gets or sets the stream URL.
    /// </summary>
    [JsonPropertyName("url")]
    public string Url { get; set; } = string.Empty;

    /// <summary>
    /// Gets or sets the streaming protocol (e.g., HLS, DASH).
    /// </summary>
    [JsonPropertyName("protocol")]
    public string? Protocol { get; set; }

    /// <summary>
    /// Gets or sets the quality level (e.g., HD, SD).
    /// </summary>
    [JsonPropertyName("quality")]
    public string? Quality { get; set; }

    /// <summary>
    /// Gets or sets the streaming method.
    /// </summary>
    [JsonPropertyName("streaming")]
    public string? Streaming { get; set; }

    /// <summary>
    /// Gets or sets the MIME type.
    /// </summary>
    [JsonPropertyName("mimeType")]
    public string? MimeType { get; set; }

    /// <summary>
    /// Gets or sets the encoding.
    /// </summary>
    [JsonPropertyName("encoding")]
    public string? Encoding { get; set; }

    /// <summary>
    /// Gets or sets whether DRM is required.
    /// </summary>
    [JsonPropertyName("drmList")]
    public object? DrmList { get; set; }

    /// <summary>
    /// Gets a value indicating whether this resource is playable (not DRM-protected).
    /// </summary>
    [JsonIgnore]
    public bool IsPlayable => DrmList == null || DrmList.ToString() == "[]";
}
