module JamRuby
  class AffiliateDistribution < ActiveRecord::Base


    belongs_to :sale_line_item, class_name: 'JamRuby::SaleLineItem'
    belongs_to :affiliate_referral, class_name: 'JamRuby::AffiliatePartner', foreign_key: :affiliate_referral_id

    validates :affiliate_referral, presence:true
    validates :affiliate_referral_fee_in_cents, numericality: {only_integer: false}

    def self.create(affiliate_referral, fee_in_cents, sale_line_item)
      distribution = AffiliateDistribution.new
      distribution.affiliate_referral = affiliate_referral
      distribution.affiliate_referral_fee_in_cents = fee_in_cents
      distribution.sale_line_item = sale_line_item
      distribution
    end
  end
end
