# == Schema Information
#
# Table name: approved_firmwares
#
#  id          :integer          not null, primary key
#  version     :string(255)
#  url         :text
#  created_at  :datetime
#  updated_at  :datetime
#  upload_time :string(255)
#

class ApprovedFirmware < ActiveRecord::Base
  include PublicActivity::Model

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

  tracked assumed_by: proc {|controller, model| controller.user_assumed_by if controller}
  
  belongs_to :organisation
  belongs_to :upgrade_data
  belongs_to :hardware_category
  validates :version, presence: true, uniqueness: true
  validates :upgrade_data_id, presence: true

  def json_build
    {id: self.id, upgrade_data_id: self.upgrade_data_id, version: self.version, approved_hardware_models: self.approved_hardware_models, organisation_id: self.organisation_id, hardware_category_id: self.hardware_category_id, schedule_time_slot: self.schedule_time_slot}
  end
  
end
