defmodule Towerops.Profiles.DeviceOid do
  @moduledoc """
  Schema for device identification OIDs.
  Maps device info fields (serial_number, firmware_version, etc.) to MIB names.
  """

  use Ecto.Schema

  import Ecto.Changeset

  alias Towerops.Profiles.DeviceProfile

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

  schema "profile_device_oids" do
    field :field, :string
    field :mib_name, :string

    belongs_to :profile, DeviceProfile, foreign_key: :profile_id

    timestamps(type: :utc_datetime)
  end

  def changeset(device_oid, attrs) do
    device_oid
    |> cast(attrs, [:field, :mib_name, :profile_id])
    |> validate_required([:field, :mib_name, :profile_id])
    |> unique_constraint([:profile_id, :field])
  end
end
