using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace AxCopilot.ViewModels;

public class RegisteredModelRow : INotifyPropertyChanged
{
	private string _alias = "";

	private string _encryptedModelName = "";

	private string _service = "ollama";

	private string _endpoint = "";

	private string _apiKey = "";

	private string _authType = "bearer";

	private string _cp4dUrl = "";

	private string _cp4dUsername = "";

	private string _cp4dPassword = "";

	public string Alias
	{
		get
		{
			return _alias;
		}
		set
		{
			_alias = value;
			OnPropertyChanged("Alias");
		}
	}

	public string EncryptedModelName
	{
		get
		{
			return _encryptedModelName;
		}
		set
		{
			_encryptedModelName = value;
			OnPropertyChanged("EncryptedModelName");
			OnPropertyChanged("MaskedModelName");
		}
	}

	public string Service
	{
		get
		{
			return _service;
		}
		set
		{
			_service = value;
			OnPropertyChanged("Service");
			OnPropertyChanged("ServiceLabel");
		}
	}

	public string Endpoint
	{
		get
		{
			return _endpoint;
		}
		set
		{
			_endpoint = value;
			OnPropertyChanged("Endpoint");
			OnPropertyChanged("EndpointDisplay");
		}
	}

	public string ApiKey
	{
		get
		{
			return _apiKey;
		}
		set
		{
			_apiKey = value;
			OnPropertyChanged("ApiKey");
		}
	}

	public string AuthType
	{
		get
		{
			return _authType;
		}
		set
		{
			_authType = value;
			OnPropertyChanged("AuthType");
			OnPropertyChanged("AuthLabel");
		}
	}

	public string Cp4dUrl
	{
		get
		{
			return _cp4dUrl;
		}
		set
		{
			_cp4dUrl = value;
			OnPropertyChanged("Cp4dUrl");
		}
	}

	public string Cp4dUsername
	{
		get
		{
			return _cp4dUsername;
		}
		set
		{
			_cp4dUsername = value;
			OnPropertyChanged("Cp4dUsername");
		}
	}

	public string Cp4dPassword
	{
		get
		{
			return _cp4dPassword;
		}
		set
		{
			_cp4dPassword = value;
			OnPropertyChanged("Cp4dPassword");
		}
	}

	public string AuthLabel => (_authType == "cp4d") ? "CP4D" : "Bearer";

	public string EndpointDisplay => string.IsNullOrEmpty(_endpoint) ? "(기본 서버)" : _endpoint;

	public string MaskedModelName => string.IsNullOrEmpty(_encryptedModelName) ? "(미등록)" : "••••••••";

	public string ServiceLabel => (_service == "vllm") ? "vLLM" : "Ollama";

	public event PropertyChangedEventHandler? PropertyChanged;

	protected void OnPropertyChanged([CallerMemberName] string? n = null)
	{
		this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(n));
	}
}
