namespace EDPlayerJournal.Entries;

public class FileHeaderEntry : Entry {
    /// <summary>
    /// File part.
    /// </summary>
    public ulong Part { get; set; } = 1;

    /// <summary>
    /// Local language of the file.
    /// </summary>
    public string? Language { get; set; }

    /// <summary>
    /// Whether the file is for an Odyssey version
    /// </summary>
    public bool Odyssey { get; set; } = false;

    /// <summary>
    /// Game version in question (3.8 or 4.0)
    /// </summary>
    public string GameVersion { get; set; } = "3.8";

    /// <summary>
    /// Build version (SVN revision number).
    /// </summary>
    public string? Build { get; set; }

    /// <summary>
    /// Returns true if the version is legacy (3.X)
    /// <summary>
    public bool IsLegacy {
        get {
            return GameVersion.StartsWith("3.");
        }
    }

    /// <summary>
    /// Returns true if the version is live (4.x)
    /// </summary>
    public bool IsLive {
        get { return !IsLegacy; }
    }

    protected override void Initialise() {
        Part = JSON.Value<ulong?>("part") ?? 1;
        Language = JSON.Value<string?>("language") ?? string.Empty;
        // If this entry is not there then its a legacy entry
        Odyssey = JSON.Value<bool?>("Odyssey") ?? false;
        GameVersion = JSON.Value<string?>("gameversion") ?? "3.8";
        Build = JSON.Value<string?>("build");
    }
}
