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

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

      add :equipment_id, references(:equipment, type: :binary_id, on_delete: :delete_all),
        null: false

      add :event_type, :string, null: false
      add :severity, :string, null: false
      add :message, :text, null: false
      add :metadata, :map, default: %{}
      add :occurred_at, :utc_datetime, null: false

      timestamps(type: :utc_datetime, updated_at: false)
    end

    create index(:equipment_events, [:equipment_id])
    create index(:equipment_events, [:equipment_id, :occurred_at])
    create index(:equipment_events, [:event_type])
    create index(:equipment_events, [:occurred_at])
  end
end
