#include "employee.h"
#include "minmax.h"
#include <iostream>
#include <iomanip>

using namespace std;

template <typename ItemType>
ItemlyWorker<ItemType>::
   ItemlyWorker(const char first[] /* = "" */,
                const char last[]  /* = "" */,
                double wage_per    /* = 0  */,
                const ItemType & quant     /* = 0  */)
    : Employee(first, last), wage_per_item(::max(wage_per, 0.0)),
      item_quantity(::max(quant, ItemType()))
{ }

template <typename ItemType>
ItemlyWorker<ItemType>::
   ItemlyWorker(const ItemlyWorker<ItemType> & worker)
    : Employee(worker), wage_per_item(worker.wage_per_item),
      item_quantity(worker.item_quantity)
{ }

template <typename ItemType>
ItemlyWorker<ItemType>::
   ~ItemlyWorker() { }

template <typename ItemType>
ItemlyWorker<ItemType> & ItemlyWorker<ItemType>::
   operator = (const ItemlyWorker & worker)
{
   Employee::operator =(worker);
   wage_per_item = worker.wage_per_item;
   item_quantity = worker.item_quantity;
   return *this;
}

template <typename ItemType>
void ItemlyWorker<ItemType>::
   set_wage_per(double wage_per)
{
   wage_per_item = ::max(wage_per, 0.0);
   return;
}

template <typename ItemType>
void ItemlyWorker<ItemType>::
   set_quantity(const ItemType & quant)
{
   item_quantity = ::max(quant, ItemType());
   return;
}

template <typename ItemType>
double ItemlyWorker<ItemType>::
   earnings(void) const
{
   return wage_per_item * item_quantity;
}

template <typename ItemType>
void ItemlyWorker<ItemType>::
   print(ostream & out) const
{
   out << endl
       << setw(25) << "Itemly:  ";
   Employee::print(out);
   return;
}
