using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Text;

namespace CafeTerrace.Models.DataBase
{
    public class User
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string UserName { get; set; }
        public string Phone { get; set; }
        public string Password { get; set; }
        public string ConfirmPassword { get; set; }
        public GenderType Gender { get; set; }

        public int GenderIndex
        {
            get
            {
                switch (Gender)
                {
                    case GenderType.Female:
                        return 1;
                        break;
                    case GenderType.Male:
                        return 0;
                        break;
                    default:
                        return 1;
                        break;
                }
            }
        }
        public DateTime BirthDate { get; set; }
        public string JobId { get; set; }
        public string JobType { get; set; }

        private string _birthDateString;

        public string BirthDatePersian
        {
            get
            {
                if (string.IsNullOrEmpty(_birthDateString))
                {
                    
                    PersianCalendar pc = new PersianCalendar();
                    _birthDateString = string.Format("{0}/{1}/{2}", pc.GetYear(BirthDate), pc.GetMonth(BirthDate), pc.GetDayOfMonth(BirthDate));
                }
                    return _birthDateString;
            }
            set { _birthDateString = value; }
        }

        public string BirthDataString { get; set; }
        public virtual ICollection<Order> Orders { get; set; }
        public virtual ICollection<Favorite> Favorites { get; set; }
        public virtual ICollection<Rate> Rates { get; set; }
        public virtual ICollection<ClubGradeUser> ClubGradeUsers { get; set; }
        public virtual Job Job { get; set; }

        public string FullName
        {
            get { return FirstName +" "+ LastName; }
        }
        public string NameWClub
        {
            get
            {
                if (ClubGradeUsers != null && ClubGradeUsers.Count > 0)
                    return $"{FullName} ({ClubGradeUsers.FirstOrDefault().ClubGrade.GradeName}) ";
                else
                    return FullName;
            }
        }
        public int OrderCount
        {
            get
            {
                return Orders != null ? Orders.Count : 0;
            }
        }
        public long OrderAmountCount
        {
            get
            {
                return Orders != null ? Orders.Sum(o=>o.Fish.TotalAmount) : 0;
            }
        }

        public int RatesCount
        {
            get { return Rates != null ? Rates.Count : 0; }
        }
    }

    public enum GenderType
    {
        [Display(Name = "مرد")]
        Male = 1,

        [Display(Name = "زن")]
        Female = 2
    }

}
