using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Platnosci.Core.Linq;
using System.Threading;
using System.Globalization;
using System.Web.Mvc;
using System.Configuration;
using System.Security.Principal;


namespace Platnosci.Models
{
    public class FunkcjePlatnosci
    {
        private const string EUR = "978";
        private const string GBP = "826";
        private const string USD = "789";
        private const string PLN = "985";

        public string BruttoToString(decimal? kwota, decimal? waluta, string miano)
        {
            string brutto = String.Format("{0:0.00}", kwota.ToString().Replace(",", ".")) + " PLN ";
            if (waluta > 0 && (miano != "" || miano != "PLN"))
            {
                brutto += "(" + (waluta.ToString()).Replace(",", ".") + " " + miano + ")";
            }
            return brutto;
        }
        public bool UserIdentity(vPlatnosciEcard platnosc, string userName)
        {
            if (platnosc != null && platnosc.nip == userName)
            {
                return true;
            }
            return false;
        }
        public Waluta setAmount(vPlatnosciEcard platnosc){
            
            Waluta waluta = new Waluta();
            waluta.Amount = Convert.ToInt32(platnosc.Brutto * 100);
            
            if (String.IsNullOrEmpty(platnosc.waluta_miano) || platnosc.waluta_miano == "PLN")
            {                
                waluta.Currency = PLN;
            }
            else
            {
                if (platnosc.waluta_miano == "EUR") 
                {
                    waluta.Currency = EUR;
                }
                else if (platnosc.waluta_miano == "GBP")
                {
                    waluta.Currency = GBP;
                }
                else if (platnosc.waluta_miano == "USD")
                {
                    waluta.Currency = USD;
                }
            }
            return waluta;
        }
        public string setLanguage(string lang){

            if (lang == "pl" || lang == "en" || lang == "de" || lang == "it" || lang == "fr")
            {
                if (lang != Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToLower())
                {
                    string culture = "pl-PL";
                    if (lang == "pl") culture = "pl-PL";
                        else if (lang == "en") culture = "en-US";
                        else if (lang == "de") culture = "de-DE";
                        else if (lang == "it") culture = "it-IT";
                        else if (lang == "fr") culture = "fr-FR";

                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
                }
            }
            string pom = CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToLower();
            return pom;
        }
        public string setTitle()
        {
            string str = "";
            string css = ConfigurationManager.AppSettings["Css"].ToString();
            
            if (css == "truck") str = HttpContext.GetGlobalResourceObject("tlumaczenia", "adresTruck").ToString() + " - ";
                else if (css == "admoto") str = HttpContext.GetGlobalResourceObject("tlumaczenia", "adresAdmoto").ToString() + " - ";
            
            return str;
        }
        public void SetUserLogger(string nip, string faktura){
            
            string User = nip + "-" + faktura;
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(User, ""), null);
        }
        public ErrorViewData InitErrorViewData(string errortxt)
        {
            ErrorViewData er = new ErrorViewData();
            er.Error = errortxt;
            return er;
        }
        
    }
}

        
