module JamRuby
  class UserBlacklist < ActiveRecord::Base

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

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

    validates :user, presence: true

    validates_uniqueness_of :user_id

    def self.banned(user)
      UserBlacklist.where("user_id = '#{user.id}' AND user_id NOT IN (SELECT white.user_id FROM user_whitelists white WHERE white.user_id = '#{user.id}')").count >= 1
    end

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

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

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

    def to_s
      user
    end
  end
end
