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

public record VersionSearchParams
{
    public bool ReleaseTypeAllowed;
    public bool SnapshotTypeAllowed;
    public bool OldTypeAllowed;
    public bool OtherTypeAllowed;
}

public class GameVersionCatalog
{ 
    [JsonRequired] public List<RemoteVersionDescriptorProps> versions { get; set; } = new();
    
    /// <returns>empty list if couldn't find any remote versions</returns>
    public List<RemoteVersionDescriptorProps> GetDownloadableVersions(VersionSearchParams p)
    {
        var _versionPropsList = new List<RemoteVersionDescriptorProps>();
        foreach (var r in versions)
        {
            bool match = r.type switch
            {
                "release" => p.ReleaseTypeAllowed,
                "snapshot" => p.SnapshotTypeAllowed,
                "old_alpha" or "old_beta" => p.OldTypeAllowed,
                _ => p.OtherTypeAllowed
            };
            if(match)
                _versionPropsList.Add(r);
        }
        return _versionPropsList;
    }
}

public class AssetProperties
{
    [JsonRequired] public string hash { get; set; } = "";
    [JsonRequired] public int size { get; set; }
}

public class AssetIndex
{
    [JsonRequired] public Dictionary<string, AssetProperties> objects { get; set; } = new();
}

public class RemoteVersionDescriptorProps
{
    [JsonRequired] public string id { get; set; } = "";
    [JsonRequired] public string url { get; set; } = "";
    [JsonRequired] public string type { get; set; } = "";
    public string sha1 { get; set; } = "";
    public DateTime time { get; set; }
    public DateTime releaseTime { get; set; }
}
