# == Schema Information
#
# Table name: roles
#
#  id            :integer          not null, primary key
#  name          :string(255)
#  resource_id   :integer
#  resource_type :string(255)
#  created_at    :datetime
#  updated_at    :datetime
#

class Role < ActiveRecord::Base
  has_many :unities, dependent: :destroy
  has_many :users, -> { uniq }, through: :unities
  has_many :location_networks, -> { uniq }, through: :unities


  validates :name, uniqueness: true

  #Note: !!!!!! Role name change should reflect here also !!!!!!
  ROLES_NAME_MAPPING = {"monitor_only" => "Monitor only", "network_monitor" => "Network Monitor", "customer_care_devices_senior_experts" => "Customer Care - Devices Senior Experts", "customer_care_devices_experts" => "Customer Care - Devices Experts", "customer_care_devices_specialists" => "Customer Care - Devices Specialists", "customer_care_general" => "Customer Care - General", "vendor_techs" => "Vendor - Techs", "nw_onboarding_manager" => "Network Onboarding - Manager", "nw_onboarding_techs" => "Network Onboarding - Techs", "network_r&d" => "Network R&D","organization_monitor" => "Organization Monitor"}
  
  def self.api_role
    self.where(name: "api").last
  end
  
end
