using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Media.Imaging;

namespace PracticaDemoexam.Model.ItemModels
{
    public class AgentModel
    {
        public Agent Agent { get; set; }
        private BitmapImage _bitmap;
        public BitmapImage AgentLogo
        {
            get
            {
                _bitmap = new BitmapImage();
                _bitmap.BeginInit();
                if (string.IsNullOrEmpty(Agent.Logo) || string.IsNullOrWhiteSpace(Agent.Logo))
                {
                    _bitmap.UriSource = new Uri("\\Resources\\agents\\picture.png", UriKind.Relative);
                }
                else
                {
                    _bitmap.UriSource = new Uri("\\Resources" + Agent.Logo, UriKind.Relative);
                }
                _bitmap.EndInit();
                return _bitmap;
            }
        }
        public string AgentType
        {
            get
            {
                return Agent.AgentType.Title;
            }
        }
        public string YearSales
        {
            get
            {
                int ret = 0;
                foreach(ProductSale sale in Agent.ProductSale)
                {
                    if(DateTime.Now.Year - sale.SaleDate.Year <= 1)
                    {
                        ret += sale.ProductCount;
                    }
                }
                return ret.ToString() + " продаж за год";
            }
        }
        public string Discount
        {
            get
            {
                decimal count = 0;
                foreach (ProductSale sale in Agent.ProductSale)
                {
                    count += sale.ProductCount * sale.Product.MinCostForAgent;
                }
                if(count <= 10000)
                {
                    return "0%";
                }
                if(count <= 50000)
                {
                    return "5%";
                }
                if(count <= 150000)
                {
                    return "10%";
                }
                if (count <= 500000)
                {
                    return "20%";
                }
                else return "25%";
            }
        }
    }
}
