﻿/*
 * Copyright 2014 Mtzky
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mobitap.Properties;

namespace Mobitap.Properties
{
	/// <summary>
	/// The localized <c>Resources</c>.
	/// </summary>
	public class ResourceService : INotifyPropertyChanged
	{
		private static readonly ResourceService instance = new ResourceService();
		private ResourceService() { if (Resources.Culture == null) Culture = CultureInfo.CurrentUICulture; }
		/// <summary>Gets the singleton instance.</summary>
		public static ResourceService Current { get { return instance; } }

		private readonly Resources resources = new Resources();
		/// <summary>Gets the localized <c>Resources</c>.</summary>
		public Resources Resources { get { return this.resources; } }

		/// <summary>A property changed event</summary>
		public event PropertyChangedEventHandler PropertyChanged;
		protected virtual void RaisePropertyChanged(string propertyName = "Resources")
		{
			if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}

		internal static void SetCulture(string culture)
		{
			Current.Culture = (culture != null && 0 < culture.Length) ? CultureInfo.GetCultureInfo(culture) : null;
		}
		/// <summary>
		/// Gets the culture of <c>Resources</c>.
		/// Sets the specified culture to <c>Resources</c> and raises a property changed event.
		/// </summary>
		public CultureInfo Culture
		{
			get { return Resources.Culture ?? CultureInfo.CurrentUICulture; }
			set
			{
				Resources.Culture = (value ?? CultureInfo.CurrentUICulture);
				RaisePropertyChanged();
			}
		}
	}
}
