package functional

type ShoppingCard struct {
	items    []Item
	strategy PaymentStrategy
}

func NewShoppingCard() *ShoppingCard {
	return &ShoppingCard{}
}

func (c *ShoppingCard) AddItem(item Item) {
	c.items = append(c.items, item)
}

func (c *ShoppingCard) SetStrategy(strategy PaymentStrategy) {
	c.strategy = strategy
}

func (c *ShoppingCard) Pay() error {
	total := 0
	for _, item := range c.items {
		total += item.Price()
	}
	return c.strategy(total)
}
