using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace OF_DL.Widevine;

[Serializable]
public class ContentKey
{
    [JsonPropertyName("key_id")] public byte[] KeyID { get; set; } = [];

    [JsonPropertyName("type")] public string Type { get; set; } = "";

    [JsonPropertyName("bytes")] public byte[] Bytes { get; set; } = [];

    [NotMapped]
    [JsonPropertyName("permissions")]
    public List<string> Permissions
    {
        get => PermissionsString.Split(",").ToList();
        set => PermissionsString = string.Join(",", value);
    }

    [JsonIgnore] public string PermissionsString { get; set; } = "";

    public override string ToString() =>
        $"{BitConverter.ToString(KeyID).Replace("-", "").ToLower()}:{BitConverter.ToString(Bytes).Replace("-", "").ToLower()}";
}
