# == Schema Information
#
# Table name: radio_settings
#
#  id               :integer          not null, primary key
#  band             :string(255)
#  channel          :integer
#  power            :integer
#  radio_profile_id :integer
#  is_disable       :boolean          default(FALSE)
#  country_ie       :boolean          default(TRUE)
#  require_mode     :string(255)
#  created_at       :datetime
#  updated_at       :datetime
#

class RadioSetting < ActiveRecord::Base
  serialize :vendor_details, Hash
  serialize :valid_auto_channel, Array
  
  REQUIRE_MODE = [['gn', 'g'],['n', 'n']]
  CHANNELS_5_GHZ = ["Auto",34,36,38,40,44,46,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140,144,149,151,153,155,157,159,161,165,184,188,192,196]
  VALID_CHANNELS_5_GHZ = [34,36,38,40,44,46,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140,144,149,151,153,155,157,159,161,165,184,188,192,196]
  CHANNELS_6_GHZ = ["Auto",1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 169, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 233]
  VALID_CHANNELS_6_GHZ = [1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 169, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 233]
  CHANNELS_2_4_GHZ = (1..14).to_a.unshift("Auto")
  VALID_CHANNELS_2_4_GHZ = (1..14).to_a
  MULTICAST_RATE = ["None", "1000","2000","5500","6000","9000","11000", "12000","18000", "24000", "36000", "48000", "54000"]
  NETWORK_TYPE = ["Private network", "Private network with guest access", "Chargeable public network", "Free public network", "Personal device network", "Emergency services only network", "Test or experimental", "Wildcard"]


  belongs_to :radio_profile
  include PublicActivity::Model

  tracked owner: ->(controller, model) { controller && controller.tracked_current_user },params:
  { :attributes => proc {|controller, model_instance| {"radio_settings(#{model_instance.band})" => model_instance.changes}}},organisation_id: ->(controller, model) { controller && controller.tracked_current_user.organisation_id },:location_network_id => proc {|controller, model_instance| model_instance.radio_profile.location_network_id }

  tracked assumed_by: proc {|controller, model| controller.user_assumed_by if controller}

  def json_build
    {id: self.id, band: self.band, channel: self.channel, power: self.power, radio_profile_id: self.radio_profile_id, is_disable: self.is_disable, country_ie: self.country_ie, bandwidth: self.bandwidth, channel_utlilization: self.channel_utlilization, maximum_clients: self.maximum_clients, multiple_bssid: self.multiple_bssid, beacon_rate: self.beacon_rate, beacon_interval: self.beacon_interval, dtim_period: self.dtim_period, multicast: self.multicast, ema: self.ema, bss_color: self.bss_color, valid_auto_channel: self.valid_auto_channel}
  end

end
