defmodule Towerops.Repo.Migrations.CreateSnmpStateSensors do
  use Ecto.Migration

  def change do
    create table(:snmp_state_sensors, primary_key: false) do
      add :id, :binary_id, primary_key: true

      add :snmp_device_id, references(:snmp_devices, type: :binary_id, on_delete: :delete_all),
        null: false

      add :sensor_index, :string, null: false
      add :sensor_oid, :string, null: false
      add :sensor_descr, :string
      add :entity_type, :string
      add :state_value, :integer
      add :state_descr, :string
      add :status, :string, default: "unknown"
      add :last_checked_at, :utc_datetime
      add :metadata, :map, default: %{}

      timestamps(type: :utc_datetime)
    end

    create index(:snmp_state_sensors, [:snmp_device_id])
    create unique_index(:snmp_state_sensors, [:snmp_device_id, :sensor_index])
    create index(:snmp_state_sensors, [:status])
    create index(:snmp_state_sensors, [:entity_type])
  end
end
