class DeviceState < ApplicationRecord
  ROLES = %w[camera controller].freeze

  belongs_to :stream_session

  validates :device_role, inclusion: { in: ROLES }
  validates :device_role, uniqueness: { scope: :stream_session_id }

  def as_cable_payload
    {
      type: "device_state",
      battery: battery_level,
      network: network_type,
      bitrate: current_bitrate,
      fps: fps,
      status: stream_session.status
    }
  end
end
