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

  def change do
    create table(:preseem_fleet_profiles, 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 :manufacturer, :string, null: false
      add :model, :string, null: false
      add :firmware_version, :string
      add :device_count, :integer, null: false
      add :avg_subscribers, :float
      add :avg_qoe_score, :float
      add :avg_capacity_score, :float
      add :capacity_ceiling, :integer
      add :avg_busy_hours, :float
      add :performance_data, :map
      add :computed_at, :utc_datetime, null: false
    end

    create index(:preseem_fleet_profiles, [:organization_id])

    create unique_index(
             :preseem_fleet_profiles,
             [:organization_id, :manufacturer, :model, :firmware_version],
             name: :preseem_fleet_profiles_org_model_fw_idx
           )
  end
end
