using ReactiveUI;
using ReactiveUI.Validation.Helpers;

namespace VeloeMinecraftLauncher.Models;
public class ServerPanelModel : ReactiveValidationObject
{
    private string _name;
    private string _status;
    private string _tip;
    private string _players;
    private string _clientName;
    private string? _userClientName;

    public ServerPanelModel(string name, string status, string tip, string players, string address, string clientName)
    {
        _name = name;
        _status = status;
        _tip = tip;
        _players = players;
        Address = address;
        _clientName = clientName;
    }

    public string Name
    {
        get => _name;
        set => this.RaiseAndSetIfChanged(ref _name, value);
    }

    public string Status
    {
        get => _status;
        set => this.RaiseAndSetIfChanged(ref _status, value);
    }

    public string Tip
    {
        get => _tip;
        set => this.RaiseAndSetIfChanged(ref _tip, value);
    }

    public string Players
    {
        get => _players;
        set => this.RaiseAndSetIfChanged(ref _players, value);
    }

    public string Address { get; set; }

    public string ClientName 
    { 
        get => _clientName;
        set => this.RaiseAndSetIfChanged(ref _clientName, value);
    }

    public string? UserClientName 
    { 
        get => _userClientName;
        set 
        {
            this.RaiseAndSetIfChanged(ref _userClientName, value);
            this.RaisePropertyChanged(nameof(IsOverriden));
            this.RaisePropertyChanged(nameof(IsResetable));
        }
    }

    public bool IsOverriden => !string.IsNullOrEmpty(UserClientName);

    public bool IsResetable => IsOverriden && !string.IsNullOrEmpty(ClientName);
}

