class Reseaux < ActiveRecord::Base
  belongs_to :chef_reseau, :class_name => "Customer"
  
  has_many :reseaux_customers
  has_many :customers, :through => :reseaux_customers
  
  has_many :needs, :through => :customers
  
  has_many :offer_reseauxes
  has_many :offers, :through => :offer_reseauxes
  
  
  has_many :thing_conversations, :as => :thing
  
  has_many :conversations, :through => :thing_conversations
  
  acts_as_tree
  
  
  before_create do
    self.generate_token
  end
  

  
  def generate_token
     self.token = loop do
   
    token = SecureRandom.hex(3)
    token = token.upcase
      break token unless Reseaux.exists?(token: token) or token.include?("0") or token.include?("O") or token.include?("1") or token.include?("L") or token.include?("I")
    end
  end
  

end
