using System;
using System.Collections.Generic;
using System.Linq; 

namespace TheMVCPattern.Models
{
    public class Item
    {
        public int ItemID { get; private set; } // klucz unikatowy
        public string Title { get; set; }
        public string Description { get; set; }
        public DateTime AuctionEndDate { get; set; }
        public IList<Bid> Bids { get; private set; }
        public Item()
        {
            Bids = new List<Bid>();
        }

        public void AddBid(Member memberParam, decimal amountParam)
        {
            if (Bids.Count() == 0 || amountParam > Bids.Max(e => e.BidAmount)) { 
                Bids.Add(new Bid()
                {
                    BidAmount = amountParam,
                    DatePlaced = DateTime.Now,
                    Member = memberParam
                });
            }
            else
            {
                throw new InvalidOperationException("Zbyt mała wartość oferty");
            } 

        } 

    }
}
