/*
 * This files contains some of the low level details of the Car class
 * implementation.
 *
 * THERE IS NO REASON FOR YOU TO READ OR EDIT THIS FILE
 */

#include "Car.h"
#include <sstream>

Car::Car(std::string c, int doors) {
  valid = true;
  broken = false;
  color = c;
  numDoors = doors;
}


Car::Car(const Car& other) {
  // NOT ALLOWED TO COPY A CAR
    std::cout << "ERROR.  A request has been made to copy a car," << std::endl;
    std::cout << "  however cars cannot be modeled off another car." << std::endl;
  valid = false;
}

Car& Car::operator=(const Car& other) {
  // NOT ALLOWED TO ASSIGN ONE CAR TO ANOTHER
  if (this!=&other) {
    std::cout << "ERROR.  A request has been made to assign a car," << std::endl;
    std::cout << "  however cars cannot be modeled off another car." << std::endl;
    valid = false;
  }
  return *this;
}


std::string Car::toString() const {
  std::stringstream result;
  if (valid) 
    result << color << " "<< numDoors << "-door car " <<
      (broken ? "(broken)" : "(good condition)");
  else
    result << "INVALID CAR";
  return result.str();
}

void Car::fixIt() {
  broken = false;
}

void Car::breakIt() {
  broken = true;
}


std::ostream& operator<<(std::ostream& out, const Car& c) {
  out << c.toString();
  return out;
}
