class Product < ApplicationRecord
	validates_presence_of :quantity, :cost
	belongs_to :supplier, optional: true

	def conekta_key
		"#{quantity.to_i}_Mes#{'es' if quantity.to_i>1}_PlanIntegral"
	end

	def titulo
		if category == "plan"
			return "#{quantity} Mes#{'es' if quantity.to_i>1}"
		else
			_name = title
			_name += " #{flavour}" if flavour.present?
			_name += " (#{quantity})" if quantity.present?
			return _name
		end
	end

	def conekta_amount
		return total * 100
	end

	def unit_price
		conekta_amount / quantity.to_i
	end

	def total
		return (cost - (discount||0))
	end

end