// Header file for the ShoppingList class.

#ifndef SHOPPING_LIST_H
#define SHOPPING_LIST_H

#include <string>
#include "Item.h"

const int MAX_NUM_ITEMS = 100;


/*
 * Purpose:
 *   Represents a shopping list, a list of items where there is
 *   a quantity and a cost associated with each item. Each item
 *   in the list is located at a unique position from 0 (front
 *   of the list) to current number items in the list minus one.
 *
 * Data:
 *   1) Fixed array of items of size MAX_NUM_ITEMS
 *   2) Count of the current number of items in the list
 */
class ShoppingList {

public:

  ShoppingList() : size(0) {;}

  /*
   * Purpose:
   *   Inserts anItem into the list at position pos. Other items
   *   in the list will "slide down" to make room for anItem. 0
   *   is the first position in the list and the end of list has
   *   a position equal to the number of items in the list.
   *
   * Preconditions:
   *   1) list not full
   *   2) 0 <= pos <= number of items in the list
   *
   * Postconditions:
   *   1) anItem is added to the list at position pos
   *   2) items in the list from position pos on all have their
   *      position incremented by 1.
   *   3) number of items in the list is incremented by 1
   *
   * Calls:
   *   assert, ShoppingList::isFull
   */
  void insert(const Item & anItem, int pos);

  /*
   * Purpose:
   *   Returns a copy of the item at position pos, where 0 is
   *   the first poisiton.
   *
   * Preconditions:
   *   0 <= pos < the number of items in the list
   */
  Item getItemAt(int pos) const {
    assert(pos < size && pos >= 0);
    return item[pos];
  }

  bool isEmpty() const { return !size; }
  bool isFull() const { return size == MAX_NUM_ITEMS; }
  int getSize() const { return size; }

  /*
   * Purpose:
   *   Calculates and returns the total amount of money needed
   *   to purchase each item in the list. This calculation uses
   *   the quantity of each item being purchased as well.
   *
   * Calls:
   *   Item::getQuant, Item::getCost
   */
  double getTotalCost() const;

private:

  Item item[MAX_NUM_ITEMS]; // The list of items
  int size;                 // The number of items in the list
};


#endif
