/**
 * Copyright (C) 2022 by Martin Robillard. See https://codesample.info/about.html
 */
package e2.chapter6;

import java.util.ArrayList;
import java.util.List;

/**
 * A CardSource decorator that memorizes cards drawn from the
 * source.
 */
public class MemorizingDecorator implements CardSource
{
	private CardSource aElement;
	private List<Card> aDrawnCards = new ArrayList<>();

	public MemorizingDecorator(CardSource pCardSource) {
		aElement = pCardSource;
	}

	@Override
	public boolean isEmpty() {
		return aElement.isEmpty();
	}

	@Override
	public Card draw() {
		// 1. Delegate the original request to the decorated object
		Card card = aElement.draw();
		// 2. Implement the decoration
		aDrawnCards.add(card);
		return card;
	}

	@Override
	public CardSource copy() {
		MemorizingDecorator copy = new MemorizingDecorator(aElement.copy());
		copy.aDrawnCards = new ArrayList<>(aDrawnCards);
		return copy;
	}
}