using SQLite;

namespace BookReader.Models;

public class CalibreBook
{
    public string Id { get; set; } = string.Empty;
    public string Title { get; set; } = string.Empty;
    public string Author { get; set; } = string.Empty;
    public string? CoverUrl { get; set; }
    public string? DownloadUrl { get; set; }
    public string Format { get; set; } = string.Empty;
    public byte[]? CoverImage { get; set; }

    [Ignore]
    public string CoverCacheKey => $"calibre_{Id}_cover";

    [Ignore]
    public ImageSource? CoverImageSource
    {
        get
        {
            if (CoverImage != null && CoverImage.Length > 0)
                return ImageSource.FromStream(() => new MemoryStream(CoverImage));
            if (!string.IsNullOrEmpty(CoverUrl))
                return ImageSource.FromUri(new Uri(CoverUrl));
            return null;
        }
    }
}