defmodule Towerops.Profiles.SensorOid do
  @moduledoc """
  Schema for sensor discovery OIDs.
  Maps sensor types to MIB names for sensor discovery.
  """

  use Ecto.Schema

  import Ecto.Changeset

  alias Towerops.Profiles.DeviceProfile

  @primary_key {:id, :binary_id, autogenerate: true}
  @foreign_key_type :binary_id

  schema "profile_sensor_oids" do
    field :sensor_type, :string
    field :mib_name, :string
    field :sensor_descr, :string
    field :sensor_unit, :string
    field :sensor_divisor, :integer, default: 1

    belongs_to :profile, DeviceProfile, foreign_key: :profile_id

    timestamps(type: :utc_datetime)
  end

  def changeset(sensor_oid, attrs) do
    sensor_oid
    |> cast(attrs, [:sensor_type, :mib_name, :sensor_descr, :sensor_unit, :sensor_divisor, :profile_id])
    |> validate_required([:sensor_type, :mib_name, :profile_id])
  end
end
