defmodule Towerops.Gaiia.InventoryItemTest do
  use Towerops.DataCase, async: true

  import Towerops.AccountsFixtures
  import Towerops.OrganizationsFixtures

  alias Towerops.Gaiia.InventoryItem

  setup do
    user = user_fixture()
    org = organization_fixture(user.id)
    %{org: org}
  end

  describe "changeset/2" do
    test "valid with required fields", %{org: org} do
      changeset =
        InventoryItem.changeset(%InventoryItem{}, %{
          organization_id: org.id,
          gaiia_id: "item-123"
        })

      assert changeset.valid?
    end

    test "invalid without gaiia_id", %{org: org} do
      changeset =
        InventoryItem.changeset(%InventoryItem{}, %{
          organization_id: org.id
        })

      refute changeset.valid?
      assert "can't be blank" in errors_on(changeset).gaiia_id
    end

    test "accepts all optional fields", %{org: org} do
      changeset =
        InventoryItem.changeset(%InventoryItem{}, %{
          organization_id: org.id,
          gaiia_id: "item-123",
          name: "AF5XHD",
          status: "active",
          serial_number: "SN12345",
          mac_address: "AA:BB:CC:DD:EE:FF",
          ip_address: "10.0.0.1",
          model_name: "airFiber 5XHD",
          manufacturer_name: "Ubiquiti",
          category: "AP",
          assigned_account_gaiia_id: "acct-456",
          assigned_network_site_gaiia_id: "site-789",
          raw_data: %{"extra" => "data"}
        })

      assert changeset.valid?
    end
  end
end
