# reperesents the gift card you buy from the site (but physical gift card is modeled by GiftCard)
module JamRuby
  class GiftCardType < ActiveRecord::Base

    @@log = Logging.logger[GiftCardType]

    PRODUCT_TYPE = 'GiftCardType'

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

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

    def self.jam_track_5
      GiftCardType.find(JAM_TRACKS_5)
    end

    def self.jam_track_10
      GiftCardType.find(JAM_TRACKS_10)
    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
      else
        raise "unknown card type #{card_type}"
      end
    end


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

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

    def sales_region
      'Worldwide'
    end

    def to_s
      sale_display
    end
  end
end
