using System.Collections.Generic;
using UVC.Locale;
using UVC.Log;

namespace UVC.UI.Commands.Mono
{
    public class ChangeLanguageCommandMono : MonoBehaviourCommand
    {
        public override void Execute()
        {
            //언어가 2개 인경우 switch 시킴
            LocalizationManager _localizationManager = LocalizationManager.Instance;
            if (_localizationManager != null)
            {
                string _languageCode = _localizationManager.CurrentLanguage;
                List<string> allLan = _localizationManager.AvailableLanguages;
                if (allLan.Count == 0)
                {
                    ULog.Error("사용 가능한 언어가 없습니다.");
                    return;
                }

                foreach (string lang in allLan)
                {
                    if(_languageCode != lang)
                    {
                        _languageCode = lang;
                        break;
                    }
                }

                _localizationManager.SetCurrentLanguage(_languageCode);
                ULog.Debug($"언어가 {_languageCode}(으)로 변경되었습니다. (Command)");
            }
            else
            {
                ULog.Error("LocalizationManager가 ChangeLanguageCommand에 전달되지 않았습니다.");
            }
        }
    }


}
