namespace Pixiview.Resources
{
    public class PlatformCulture
    {
        public string PlatformString { get; private set; }
        public string LanguageCode { get; private set; }
        public string LocaleCode { get; private set; }

        public string Language
        {
            get { return string.IsNullOrEmpty(LocaleCode) ? LanguageCode : LanguageCode + "-" + LocaleCode; }
        }

        public PlatformCulture() : this(null) { }
        public PlatformCulture(string cultureString)
        {
            if (string.IsNullOrEmpty(cultureString))
            {
                //throw new ArgumentNullException(nameof(cultureString), "Expected culture identieifer");
                cultureString = "en";
            }

            PlatformString = cultureString.Replace('_', '-');
            var index = PlatformString.IndexOf('-');
            if (index > 0)
            {
                var parts = PlatformString.Split('-');
                LanguageCode = parts[0];
                LocaleCode = parts[parts.Length - 1];
            }
            else
            {
                LanguageCode = PlatformString;
                LocaleCode = "";
            }
        }

        public override string ToString()
        {
            return PlatformString;
        }
    }
}
