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

  def up do
    # Note: TimescaleDB features removed due to Apache license restrictions
    # Using standard PostgreSQL table instead
    create table(:snmp_interface_stats) do
      add :interface_id, references(:snmp_interfaces, type: :binary_id, on_delete: :delete_all),
        null: false

      add :if_in_octets, :bigint
      add :if_out_octets, :bigint
      add :if_in_errors, :bigint
      add :if_out_errors, :bigint
      add :if_in_discards, :bigint
      add :if_out_discards, :bigint
      add :checked_at, :utc_datetime, null: false

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

    # Create indexes for query performance
    create index(:snmp_interface_stats, [:interface_id])
    create index(:snmp_interface_stats, [:interface_id, :checked_at])
    create index(:snmp_interface_stats, [:checked_at])
  end

  def down do
    drop table(:snmp_interface_stats)
  end
end
