using System;
using UnityEngine;
using mgaia.Utils;

namespace mgaia.M2HLocalization
{
    /// <summary>
    /// Localization parser para o plugin Localization Package
    /// </summary>
    /// <owner>Victor</owner>
    public class M2HLocalizationParser : BaseLocalizationParser
    {
        public override bool Load(SystemLanguage systemLanguage)
        {
            LanguageCode languageCode = Language.LanguageNameToCode(systemLanguage);

            string languageAlias = languageCode.ToString();
            string[] supportedLanguages = Language.GetLanguages();

            if (supportedLanguages.Count(supportedLanguage => supportedLanguage.Equals(languageAlias)) == 0)
            {
                if (supportedLanguages.Length > 0)
                {
                    languageAlias = supportedLanguages[0];
                }
                else
                {
                    return false;
                }
            }

            return Language.SwitchLanguage(languageAlias);
        }

        public override string GetText(string session, string key)
        {
            return Language.Get(key, session);
        }

        public override bool ContainsSession(string session)
        {
            return Language.HasSheet(session);
        }

        public override bool ContainsKey(string session, string key)
        {
            return Language.Has(key, session);
        }
    }
}