using System.Text.Json.Serialization;

namespace BrassAndSigil.Server.Models;

public sealed class Manifest
{
    [JsonPropertyName("name")]
    public string? Name { get; set; }

    [JsonPropertyName("version")]
    public string? Version { get; set; }

    [JsonPropertyName("minecraft")]
    public MinecraftSpec Minecraft { get; set; } = new();

    [JsonPropertyName("loader")]
    public LoaderSpec? Loader { get; set; }

    [JsonPropertyName("files")]
    public List<ManifestFile> Files { get; set; } = new();
}

public sealed class MinecraftSpec
{
    [JsonPropertyName("version")] public string Version { get; set; } = "";
}

public sealed class LoaderSpec
{
    [JsonPropertyName("type")]    public string Type    { get; set; } = "vanilla";
    [JsonPropertyName("version")] public string Version { get; set; } = "";
}

public sealed class ManifestFile
{
    [JsonPropertyName("path")] public string  Path { get; set; } = "";
    [JsonPropertyName("url")]  public string  Url  { get; set; } = "";
    [JsonPropertyName("sha1")] public string? Sha1 { get; set; }
    [JsonPropertyName("size")] public long?   Size { get; set; }

    /// <summary>
    /// "both" (default), "client", or "server". Server skips "client" files;
    /// launcher skips "server" files. Null/missing = "both".
    /// </summary>
    [JsonPropertyName("side")] public string? Side { get; set; }
}

public sealed class PackLock
{
    [JsonPropertyName("name")]      public string  Name      { get; set; } = "";
    [JsonPropertyName("version")]   public string  Version   { get; set; } = "";
    [JsonPropertyName("minecraft")] public string  Minecraft { get; set; } = "";
    [JsonPropertyName("loader")]    public LoaderSpec Loader { get; set; } = new();
    [JsonPropertyName("mods")]      public List<LockedMod> Mods { get; set; } = new();
}

public sealed class LockedMod
{
    [JsonPropertyName("source")]    public string  Source    { get; set; } = "";
    [JsonPropertyName("slug")]      public string? Slug      { get; set; }
    [JsonPropertyName("versionId")] public string? VersionId { get; set; }
    [JsonPropertyName("fileId")]    public string? FileId    { get; set; }
    [JsonPropertyName("version")]   public string  Version   { get; set; } = "";
    [JsonPropertyName("path")]      public string  Path      { get; set; } = "";
    [JsonPropertyName("url")]       public string  Url       { get; set; } = "";
    [JsonPropertyName("sha1")]      public string  Sha1      { get; set; } = "";
    [JsonPropertyName("size")]      public long    Size      { get; set; }
    [JsonPropertyName("side")]      public string? Side      { get; set; }
}
