#Pseudocode
#create class named Car
#upon initialization of new object from Car class, allow ability to set its model and color.
#define a distance variable that can be edited
#define a speed variable that can be read based on acceleration or deceleration
#give left and right methods (not sure what used for yet)
#give accelerate and decelerate methods that increase or decrease speed and affect distance.
#define total distance travelled as speed * time and be able to read that.
#create time variable that counts how many moves you have gone for directions.
#define method which will immediately bring speed down to 0 in order for car to "stop"
#define a method which will show the last action of the car (not sure how to do this yet)
=begin
class Car 

attr_accessor :model, :color, :distance
attr_reader :distance_travelled, :speed, :time, :direction 

	def initialize(model, color, direction)
		unless direction.downcase == ('north' || 'south' || 'east' || 'west')
			raise ArgumentError.new ("Starting direction must be North, South, East, or West.")
		end
		@model = model
		@color = color
		@distance_travelled = 0
		@speed = 0
		@time = 0
		@direction = direction
	end

 	def set_distance(miles)
 		@distance = miles
 		p "New distance added: #{@distance} miles"
 	end

 	def check_speed
 		p "Current speed: #{@speed} mph"
 	end

	

	def drive
		unless @distance >= 0 || @speed >= 0
			raise ArgumentError.new("set distance and speed to be greater than 0")
		end
		
		p "You drove #{@distance} miles at #{@speed} mph."

		@distance_travelled += @distance

		@distance = 0
	end

	def accelerate(mph)
		@speed += mph
		p "Current Speed: #{@speed} mph"
	end

	def decelerate(mph)
		@speed -= mph
	end

	def stop
		@speed = 0
		p "Car stopped. Current Speed: #{@speed} mph"
	end

	def turn(turn_direction)
		unless turn_direction.downcase === 'left' || turn_direction.downcase === 'right'
			raise ArgumentError.new("can only turn left or right")
		end

		case @direction

		when 'north'
			if turn_direction === 'left'
				@direction = 'west'
			else
				@direction = 'east'
			end
			

		when 'south'
			if turn_direction === 'left'
				@direction = 'east'
			else
				@direction = 'west'
			end
			

		when 'east'
			if turn_direction === 'left'
				@direction = 'north'
			else
				@direction = 'south'
			end
			

		when 'west'
			if turn_direction === 'left'
				@direction = 'south'
			else
				@direction = 'north'
			end
		else
			p "I don't know that direction"
		end

		p "Turned #{turn_direction}, now travelling #{@direction}."
	end
end
=end

#Refactored Solution


class Pizza

attr_accessor :pizza_distance_travelled
attr_reader :pizza_name

	def initialize(cheese,sauce)
		@temperature = ['cold','lukewarm','warm','hot'][rand(0..3)]
		@pizza_distance_travelled = 0
		@pizza_name = "#{@temperature} #{sauce}, #{cheese} pizza"
	end

end

class Car 

attr_accessor :model, :color

	def initialize(model, color, direction)
		
		unless ['north', 'south','east','west'].include? direction.downcase
			raise ArgumentError.new ("Starting direction must be North, South, East, or West.")
		end

		@model = model
		@color = color
		@distance_travelled = 0
		@speed = 0
		@direction = direction
		@direction_wheel = ['north','east','south','west']
		@pizza_compartment = []
	end

	def list_pizzas
		puts "Pizza compartment now: "
		counter = 1
		@pizza_compartment.each do|stuff|
					puts counter.to_s+") "+ stuff.pizza_name
				counter +=1
			end
	end


	def get_pizza(pizza_object)
		@pizza_compartment.push(pizza_object)
		puts "Added a #{pizza_object.pizza_name} to the pizza_compartment!"
		list_pizzas
	end

	def deliver_pizza
		puts "You delievered a" + @pizza_compartment[0].pizza_name
		@pizza_compartment.shift
		list_pizzas		
	end		


 	def check_speed
 		p "Current speed: #{@speed} mph"
 	end

	def drive(distance)
		unless @speed >= 0
			raise ArgumentError.new("Speed must be to be greater than 0")
		end
	
		p "You drove #{distance} miles heading #{@direction} at #{@speed} mph."

		@distance_travelled += distance


		@pizza_compartment.each	do |x|
			x.pizza_distance_travelled += distance
		end

	end

	def change_speed(mph)
		oldspeed = @speed
		@speed += mph
		if mph > 0
			p "Accelerating from #{oldspeed} mph to #{@speed} mph."
		else
			p "Decelerating from #{oldspeed} mph to #{@speed} mph."
		end
	end

	def stop
		@speed = 0
		p "Car stopped. Current Speed: #{@speed} mph"
	end

	def turn(turn_direction)
		unless turn_direction.downcase === 'left' || turn_direction.downcase === 'right'
			raise ArgumentError.new("can only turn left or right")
		end	

		case turn_direction

		when 'right'
			if @direction === 'west' 
				new_direction = 'north'
			else
				new_direction = @direction_wheel[@direction_wheel.index(@direction)+1]
			end
		when 'left'
		if @direction === 'north' 
			new_direction = 'west'
		else
			new_direction = @direction_wheel[@direction_wheel.index(@direction)-1]
		end
		end
		
		@direction = new_direction
		p "Turned #{turn_direction}, now travelling #{new_direction}."

	end

	def log_total_distance
		puts "Total distance travelled: #{@distance_travelled} miles"
	end


end

#DRIVER CODE

margherita = Pizza.new('red sauce','mozzarella')
classic = Pizza.new('red sauce','american')
pesto = Pizza.new('pesto sauce','mozzarella')


evelyn = Car.new('mercedes','white','east')
evelyn.get_pizza(pesto)
evelyn.change_speed(25)
evelyn.drive(0.25)
evelyn.stop
evelyn.turn('right')
evelyn.change_speed(35)
evelyn.get_pizza(classic)
evelyn.drive(1.5)
evelyn.get_pizza(margherita)
evelyn.check_speed
evelyn.change_speed(-20)
evelyn.check_speed
evelyn.drive (0.25)
evelyn.deliver_pizza
evelyn.stop
evelyn.turn('left')
evelyn.change_speed(20)
evelyn.drive(1.4)
evelyn.stop
evelyn.log_total_distance

=begin
	
   What concepts did you review in this challenge?
   editing objects with instance variables, accessors, and methods

    What is still confusing to you about Ruby?
    I think i was able to review a lot of things here! I liked this challenge because I knew it dealt
    with some things I've struggled with, so it was good to practice.


    What are you going to study to get more prepared for Phase 1?
    Reread portions of Well-Grounded Rubyist for things like hashes and objects that I still find confusing.

	
=end