# reperesents the posa card you buy from the site
module JamRuby
  class PosaCardType < ActiveRecord::Base

    @@log = Logging.logger[PosaCardType]

    PRODUCT_TYPE = 'PosaCardType'


    JAM_TRACKS_5 = 'jam_tracks_5'
    JAM_TRACKS_10 = 'jam_tracks_10'
    JAM_CLASS_4 = 'jam_class_4'
    CARD_TYPES =
        [
            JAM_TRACKS_5,
            JAM_TRACKS_10,
            JAM_CLASS_4
        ]

    validates :card_type, presence: true, inclusion: {in: CARD_TYPES}

    def self.jam_track_5
      PosaCardType.find(JAM_TRACKS_5)
    end

    def self.jam_track_10
      PosaCardType.find(JAM_TRACKS_10)
    end

    def self.jam_class_4
      PosaCardType.find(JAM_CLASS_4)
    end


    def name
      sale_display
    end

    def variant_price(variant = nil)
      price
    end

    def price
      if card_type == JAM_TRACKS_5
        10.00
      elsif card_type == JAM_TRACKS_10
        20.00
      elsif card_type == JAM_CLASS_4
        49.99
      else
        raise "unknown card type #{card_type}"
      end
    end


    def sale_display(variant = nil)
      if card_type == JAM_TRACKS_5
        'JamTracks Card (5)'
      elsif card_type == JAM_TRACKS_10
        'JamTracks Card (10)'
      elsif card_type == JAM_TRACKS_10
        'JamClass Card (4)'
      else
        raise "unknown card type #{card_type}"
      end
    end

    def plan_code
      if card_type == JAM_TRACKS_5
        "jamtrack-posacard-5"
      elsif card_type == JAM_TRACKS_10
        "jamtrack-posacard-10"
      elsif card_type == JAM_CLASS_4
        "jamclass-posacard-4"
      else
        raise "unknown card type #{card_type}"
      end
    end

    def sales_region
      'Worldwide'
    end

    def to_s
      sale_display
    end
  end
end
