using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Session1
{
    public partial class Agent
    {
        public string AgentBackground
        {
            get
            {
                if (AgentSaleSize == 25)
                    return "LightGreen";
                else
                    return "White";
            }
        }

        public string AgentImage
        {
            get
            {
                if (Logo != "")
                    return Logo;
                else
                    return @"\agents\picture.png";
            }
        }
        public int AgentSaleSize
        {
            get
            {
                var salesList = ProductSale.Where(x => x.AgentID == ID).ToList();
                float salesCost = 0;
                foreach (var sale in salesList)
                {
                    var days = DateTime.Now - sale.SaleDate.Date;
                    if (days.TotalDays <= 365)
                        salesCost += sale.ProductCount * (float)sale.Product.MinCostForAgent;
                }
                if (salesCost <= 10000)
                    return 0;
                else if (salesCost <= 50000)
                    return 5;
                else if (salesCost <= 150000)
                    return 10;
                else if (salesCost <= 500000)
                    return 20;
                else
                    return 25;
            }
        }
        public string AgentSaleSizeString
        {
            get
            {
                return AgentSaleSize + "%";
            }
        }
        public string AgentSales
        {
            get
            {
                var salesList = ProductSale.ToList();
                int sales = 0; 
                foreach(var sale in salesList.Where(x => x.AgentID == ID))
                {
                    var days = DateTime.Now - sale.SaleDate.Date;
                    if (days.TotalDays <= 365)
                        sales += sale.ProductCount;
                }
                return sales.ToString() + " продаж за год";
            }
        }

        public string AgentPriority
        {
            get
            {
                return "Приоритет: " + Priority;
            }
        }
    }
}
