using System.Collections.ObjectModel;

namespace Updater;

public record Argumets
{
    public string Process { get; set; } = default!;
    private string? l = null;

    public string Loc
    {
        get => l;
        set
        {
            if (goodarg(value)) l = value;
        }
    }
    private string d = "";

    public string RemoteDirectory
    {
        get
        {
            return d;
        }
        set
        {
            d = value;
        }
    }
    public string? Branch { get; set; } = default!;
    public string LocalDirectory { get; set; } = default!;
    public string DLL { get; set; } = default!;
    public string? Version { get; set; } = default!;
    public string? Platform { get; set; } = default!;
    public bool SeflContaind { get; set; } = false;

    public string? UriPlatform
    {
        get
        {
            if (goodarg(Platform)) return $"&platform={Platform}";
            return "";
        }
    }
    public string? UriSeflContaind
    {
        get
        {
            if (goodarg(SeflContaind.ToString())) return $"&selfcontained={SeflContaind.ToString().ToLower()}";
            return "";
        }
    }
    public string? UriBranch
    {
        get
        {
            if (goodarg(Branch)) return $"&branch={Branch}";
            return "";
        }
    }
    public string? UriVersion
    {
        get
        {
            if (goodarg(Version) && Version is not null) return $"&version={Version}";
            return "";
        }
    }
    public List<string>? args { get; set; } = default!;
    public ReadOnlyCollection<string>? args_raw
    {
        get
        {
            List<string> remp = new();

            void addarg(string command, string val)
            {
                remp.Add("--" + command);
                remp.Add(val);
            }

            if (goodarg(Process)) addarg(nameof(Process), Process!);
            if (goodarg(Branch)) addarg(nameof(Branch), Branch!);
            if (goodarg(RemoteDirectory)) addarg(nameof(RemoteDirectory), RemoteDirectory!);
            if (goodarg(LocalDirectory)) addarg(nameof(LocalDirectory), LocalDirectory!);
            if (goodarg(DLL)) addarg(nameof(DLL), DLL!);
            if (goodarg(Version)) addarg(nameof(Version), Version!);
            foreach (string arg in args!) remp.Add(arg);
            return remp.AsReadOnly();
        }
    }

    private bool goodarg(string? arg)
    {
        return !(string.IsNullOrEmpty(arg) || string.IsNullOrWhiteSpace(arg));
    }
}
