using System;
using System.IO;
using API.Entities.Enums;
using API.Entities.Interfaces;
namespace API.Entities;
/// 
/// Represents a wrapper to the underlying file. This provides information around file, like number of pages, format, etc.
/// 
public class MangaFile : IEntityDate
{
    public int Id { get; set; }
    /// 
    /// The filename without extension
    /// 
    public string FileName { get; set; }
    /// 
    /// Absolute path to the archive file
    /// 
    public required string FilePath { get; set; }
    /// 
    /// Number of pages for the given file
    /// 
    public int Pages { get; set; }
    public MangaFormat Format { get; set; }
    /// 
    /// How many bytes make up this file
    /// 
    public long Bytes { get; set; }
    /// 
    /// File extension
    /// 
    public string? Extension { get; set; }
    /// 
    public DateTime Created { get; set; }
    /// 
    /// Last time underlying file was modified
    /// 
    /// This gets updated anytime the file is scanned
    public DateTime LastModified { get; set; }
    public DateTime CreatedUtc { get; set; }
    public DateTime LastModifiedUtc { get; set; }
    /// 
    /// Last time file analysis ran on this file
    /// 
    public DateTime LastFileAnalysis { get; set; }
    public DateTime LastFileAnalysisUtc { get; set; }
    // Relationship Mapping
    public Chapter Chapter { get; set; } = null!;
    public int ChapterId { get; set; }
    /// 
    /// Updates the Last Modified time of the underlying file to the LastWriteTime
    /// 
    public void UpdateLastModified()
    {
        if (FilePath == null) return;
        LastModified = File.GetLastWriteTime(FilePath);
        LastModifiedUtc = File.GetLastWriteTimeUtc(FilePath);
    }
    public void UpdateLastFileAnalysis()
    {
        LastFileAnalysis = DateTime.Now;
        LastFileAnalysisUtc = DateTime.UtcNow;
    }
}