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

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

      add :organization_id, references(:organizations, type: :binary_id, on_delete: :delete_all),
        null: false

      add :preseem_id, :string, null: false
      add :name, :string
      add :mac_address, :string
      add :ip_address, :string
      add :model, :string
      add :firmware, :string
      add :capacity_score, :float
      add :qoe_score, :float
      add :rf_score, :float
      add :busy_hours, :integer
      add :airtime_utilization, :float
      add :subscriber_count, :integer
      add :device_id, references(:devices, type: :binary_id, on_delete: :nilify_all)
      add :match_confidence, :string, default: "unmatched"
      add :raw_data, :map

      timestamps(type: :utc_datetime)
    end

    create unique_index(:preseem_access_points, [:organization_id, :preseem_id])
    create index(:preseem_access_points, [:organization_id])
    create index(:preseem_access_points, [:device_id])
    create index(:preseem_access_points, [:match_confidence])
  end
end
