// Header file for the Item class.

#ifndef ITEM_H
#define ITEM_H

#include <iostream>
#include <string>
#include <cassert>


/*
 * Purpose:
 *   Represents an item in a shopping list.
 *
 * Data:
 *   1) Name of the item
 *   2) Quantity of the item to buy
 *   3) Cost of an individual item
 */
class Item {

public:

  Item(std::string n = "", int q = 0, double c = 0.0) {
    this->set(n, q, c);
  }

  /*
   * Purpose:
   *   Sets all item data. The item's name is set to n, its
   *   quantity is set to q, and its cost is set to c.
   *
   * Preconditions:
   *   1) q >= 0
   *   2) c >= 0.0
   *
   * Calls:
   *   Item::setName, Item::setQuant, Item::setCost
   */
  void set(std::string n, int q, double c);

  void setName(std::string n) { name = n; }

  /*
   * Preconditions:
   *   q >= 0
   */
  void setQuant(int q) { assert(q >= 0); quant = q; }

  /*
   * Preconditions:
   *   c >= 0.0
   */
  void setCost(double c) { assert(c >= 0.0); cost = c; }

  std::string getName()  const { return name; }
  int getQuant() const { return quant; }
  double getCost()  const { return cost; }

  /*
   * Purpose:
   *   Reads in a line of Item data text from an input stream.
   *
   * Preconditions:
   *   1) sin is open for input
   *   2) The input text is in the format:
   *        NAME\tQUANT\tCOST\n
   *      where NAME is string that may have imbedded spaces,
   *      QUANT is an integer >= 0,
   *      and COST is a floating point number >= 0.0
   */
  void input(std::istream &sin);

  /*
   * Purpose:
   *   Outputs a neatly formatted line of text to an output
   *   stream.
   *
   * Preconditions:
   *   sout is open for output
   *
   * Postconditions:
   *   A line of output is written to sout in the format:
   *     | NAME | QUANT | COST |
   *   where NAME is a string with a width of 20,
   *   QUANT is an integer with a width of 5,
   *   and COST is an floating point number with precision of 2
   *   and a total width of 6
   */
  void output(std::ostream &sout) const;

private:

  std::string name; // Name of item
  int quant;        // Quantity of item
  double cost;      // Unit cost of item
};


#endif
