class Order < ActiveRecord::Base
  belongs_to :movie_showtime
  validates_uniqueness_of :confirmation_code
  validates_presence_of :confirmation_code, :purchaser_name, :payment_type,
                        :credit_card_number, :credit_expiration_month,
                        :credit_expiration_year

  PAYMENT_TYPES = ['Visa', 'MasterCard', 'American Express']

  def validate_payment_type
    unless PAYMENT_TYPES.include?(payment_type)
      errors.add('payment_type', 
                 "Dopuszczalna jedynie patno kart #{PAYMENT_TYPES[0..-2].join(', ')} lub #{PAYMENT_TYPES[-1]}")
  end
  
  def validate
    validate_payment_type
  end
end
