using System.Linq;
// ReSharper disable CollectionNeverUpdated.Global

namespace Mlaumcherb.Client.Avalonia.классы;

public class GameVersionDescriptor
{
    [JsonRequired] public string id { get; set; } = "";
    [JsonRequired] public DateTime time { get; set; }
    [JsonRequired] public DateTime releaseTime { get; set; }
    [JsonRequired] public string type { get; set; } = "";
    [JsonRequired] public string mainClass { get; set; } = "";
    [JsonRequired] public List<Library> libraries { get; set; } = new();
    [JsonRequired] public AssetIndexProperties assetIndex { get; set; } = null!;
    [JsonRequired] public string assets { get; set; } = "";
    public Downloads? downloads { get; set; } = null;
    public JavaVersion javaVersion { get; set; } = new() { component = "jre-legacy", majorVersion = 8 };
    public string? minecraftArguments { get; set; }
    public ArgumentsNew? arguments { get; set; }
    
    // my additions
    public MyModpackRemoteProps? modpack { get; set; }
}

public class Artifact
{
    public string? path = null;
    [JsonRequired] public string url { get; set; } = "";
    [JsonRequired] public string sha1 { get; set; } = "";
    [JsonRequired] public int size { get; set; }
}

public class Os
{
    public string? name { get; set; }
    public string? arch { get; set; }
}

public class Rule
{
    [JsonRequired] public string action { get; set; } = "";
    public Os? os { get; set; }
    public Dictionary<string, bool>? features { get; set; }
}

public class LibraryDownloads
{
    public Artifact? artifact { get; set; }
    public Dictionary<string, Artifact>? classifiers { get; set; }
}

public class Extract
{
    public List<string>? exclude { get; set; }
}

public class Natives
{
    public string? linux { get; set; }
    public string? osx { get; set; }
    public string? windows { get; set; }
}

public class Library
{
    [JsonRequired] public string name { get; set; } = "";
    public List<Rule>? rules { get; set; }
    public Natives? natives { get; set; }
    public Extract? extract { get; set; }
    public LibraryDownloads? downloads { get; set; }
}

public class AssetIndexProperties
{
    [JsonRequired] public string id { get; set; } = "";
    [JsonRequired] public string url { get; set; } = "";
    [JsonRequired] public string sha1 { get; set; } = "";
    [JsonRequired] public int size { get; set; }
    [JsonRequired] public int totalSize { get; set; }
}

public class Downloads
{
    [JsonRequired] public Artifact client { get; set; } = null!;
}

public class JavaVersion
{
    [JsonRequired] public string component { get; set; } = "";
    [JsonRequired] public int majorVersion { get; set; }
}

public class ArgValue
{
    public struct StringOrArray : IEnumerable<string>
    {
        private string[] ar;

        public StringOrArray(ICollection<string> v) => ar = v.ToArray();
        public StringOrArray(string v) => ar = [v];
        public static implicit operator StringOrArray(string[] v) => new(v);
        public static implicit operator StringOrArray(string v) => new(v);
        public static implicit operator string[](StringOrArray sar) => sar.ar;
        public IEnumerator<string> GetEnumerator() => ar.AsEnumerable().GetEnumerator();
        IEnumerator IEnumerable.GetEnumerator() => ar.GetEnumerator();
    }
    public ArgValue() { }
    public ArgValue(string arg) => value = arg;
    public static implicit operator ArgValue(string arg) => new(arg);
    [JsonRequired] public StringOrArray value { get; set; } = [];
    public List<Rule> rules { get; set; } = new();
}

public class ArgumentsNew
{
    [JsonRequired] public List<ArgValue> jvm { get; set; } = new();
    [JsonRequired] public List<ArgValue> game { get; set; } = new();
}
