module JamRuby
  class UserWhitelist < ActiveRecord::Base

    attr_accessible :user_id, :notes, as: :admin
    @@log = Logging.logger[UserWhitelist]

    belongs_to :user, :class_name => "JamRuby::User"

    validates :user, presence:true

    validates_uniqueness_of :user_id

    def self.listed(user)
      UserWhitelist.where("user_id= '#{user.id}'").count == 1
    end

    def self.admin_url
      APP_CONFIG.admin_root_url + "/admin/user_whitelists/"
    end

    def admin_url
      APP_CONFIG.admin_root_url + "/admin/user_whitelists/" + id
    end

    # if a user claims a gift card or posa card, whitelist their account so they don't get messed with by fraud code
    def self.card_create(user, notes)
      user_whitelist = UserWhitelist.new
      user_whitelist.user = user
      user_whitelist.notes = notes
      user_whitelist.save
    end

    def to_s
      user
    end
  end
end