using System;
namespace Nevyn.Models
{
    public class Wallet
    {
        public int Id { get; set; }
        public int TotalAmount
        { 
            get 
            {
                return this.Kort + this.Buffert + this.Spara + this.Fonder;
            } 
        }
        public int Kort { get; set; }
        public int Buffert { get; set; }
        public int Spara { get; set; }
        public int Fonder { get; set; }

        public int MoneyUntilSalary { 
            get 
            {
                DateTime payDay = SalaryCalculator.CalculatePayDay(DateTime.Now);
                this.DaysLeftUntilSalary = (payDay - DateTime.Now).Days;
                return this.Kort / this.DaysLeftUntilSalary;
            } 
        }
        public int DaysLeftUntilSalary { get; set; }

        public class SalaryCalculator
        {
            public static DateTime CalculatePayDay(DateTime date)
            {
                // Get the 25th of the current month
                var payDay = new DateTime(date.Year, date.Month, 25);

                // If the 25th is on a weekend, get the previous Friday
                if (payDay.DayOfWeek == DayOfWeek.Saturday)
                {
                    payDay = payDay.AddDays(-1);
                }
                else if (payDay.DayOfWeek == DayOfWeek.Sunday)
                {
                    payDay = payDay.AddDays(-2);
                }

                return payDay;
            }
        }

        public void updateFromDatabase()
        {
            Classes.Mysql mysql = new Classes.Mysql();

            Wallet dbWallet = mysql.SelectWallet();
            this.Kort = dbWallet.Kort;
            this.Spara = dbWallet.Spara;
            this.Buffert = dbWallet.Buffert;            
        }

}

    public class WalletDTO
    {
        public int Id { get; set; }
        public int TotalAmount { get; set; }
        public int AmountLeftPerDay { get; set; }
        public int Kort { get; set; }
        public string Debug { get; set; }
    }

}
