package flips

import "testing"

var testFloatingIPs = FloatingIPsList{
	Objects: []RecordFloatingIP{
		{
			AccessGroupID:   "testid",
			AccessGroupName: "testname",
			CreatedAt:       "2025-09-23T08:05:59.271458Z",
			ExternalNetworkPort: ExternalNetworkPort{
				AccessGroupID:     "somegroup",
				AccessGroupName:   "somename",
				Comment:           "some comment",
				DisplayName:       "some display name",
				Enabled:           true,
				ExternalNetworkID: "someid",
				ID:                "someid",
				IPv4:              "someipv4",
				MAC:               "somemac",
				VersionID:         1111111111111,
			},
			ID: "someid",
			LogicalPort: LogicalPort{
				ID:                    "someid",
				AccessGroupID:         "someid",
				AccessGroupName:       "somename",
				AdapterMAC:            "somemac",
				AddressDetection:      false,
				Description:           "some description",
				DisplayName:           "some display name",
				Enabled:               true,
				Hypervisor:            "hypervisor",
				HypervisorDisplayName: "hypervisor display name",
				UniqueIdentifier:      "someid",
				VersionID:             1111111111111,
				CreatedAt:             "2025-09-23T08:05:59.271458Z",
				UpdatedAt:             "2025-09-23T08:05:59.271458Z",
			},
			Router: Router{
				ID:              "someid",
				AccessGroupID:   "someid",
				AccessGroupName: "somename",
				CreatedAt:       "2025-09-23T08:05:59.271458Z",
				DisplayName:     "some display name",
				Enabled:         true,
				UpdatedAt:       "2025-09-23T08:05:59.271458Z",
				VersionID:       1111111111111,
			},
			UpdatedAt: "2025-09-23T08:05:59.271458Z",
			VersionID: 1111111111111,
		},
		{
			AccessGroupID:   "testid3",
			AccessGroupName: "testname3",
			CreatedAt:       "2025-09-23T08:05:59.271458Z",
			ExternalNetworkPort: ExternalNetworkPort{
				AccessGroupID:     "somegroup",
				AccessGroupName:   "somename",
				Comment:           "some comment",
				DisplayName:       "some display name",
				Enabled:           true,
				ExternalNetworkID: "someid2",
				ID:                "someid",
				IPv4:              "someipv4",
				MAC:               "somemac",
				VersionID:         1111111111112,
			},
			ID: "someid2",
			LogicalPort: LogicalPort{
				ID:                    "someid2",
				AccessGroupID:         "someid",
				AccessGroupName:       "somename",
				AdapterMAC:            "somemac",
				AddressDetection:      false,
				Description:           "some description",
				DisplayName:           "some display name",
				Enabled:               true,
				Hypervisor:            "hypervisor",
				HypervisorDisplayName: "hypervisor display name",
				UniqueIdentifier:      "someid",
				VersionID:             1111111111112,
				CreatedAt:             "2025-09-23T08:05:59.271458Z",
				UpdatedAt:             "2025-09-23T08:05:59.271458Z",
			},
			Router: Router{
				ID:              "someid2",
				AccessGroupID:   "someid",
				AccessGroupName: "somename",
				CreatedAt:       "2025-09-23T08:05:59.271458Z",
				DisplayName:     "some display name",
				Enabled:         true,
				UpdatedAt:       "2025-09-23T08:05:59.271458Z",
				VersionID:       1111111111112,
			},
			UpdatedAt: "2025-09-23T08:05:59.271458Z",
			VersionID: 1111111111112,
		},
		{
			AccessGroupID:   "testid3",
			AccessGroupName: "testname3",
			CreatedAt:       "2025-09-23T08:05:59.271458Z",
			ExternalNetworkPort: ExternalNetworkPort{
				AccessGroupID:     "somegroup",
				AccessGroupName:   "somename",
				Comment:           "some comment",
				DisplayName:       "some display name",
				Enabled:           true,
				ExternalNetworkID: "someid3",
				ID:                "someid3",
				IPv4:              "someipv4",
				MAC:               "somemac",
				VersionID:         1111111111113,
			},
			ID: "someid3",
			LogicalPort: LogicalPort{
				ID:                    "someid3",
				AccessGroupID:         "someid",
				AccessGroupName:       "somename",
				AdapterMAC:            "somemac",
				AddressDetection:      false,
				Description:           "some description",
				DisplayName:           "some display name",
				Enabled:               true,
				Hypervisor:            "hypervisor",
				HypervisorDisplayName: "hypervisor display name",
				UniqueIdentifier:      "someid",
				VersionID:             1111111111113,
				CreatedAt:             "2025-09-23T08:05:59.271458Z",
				UpdatedAt:             "2025-09-23T08:05:59.271458Z",
			},
			Router: Router{
				ID:              "someid3",
				AccessGroupID:   "someid",
				AccessGroupName: "somename",
				CreatedAt:       "2025-09-23T08:05:59.271458Z",
				DisplayName:     "some display name",
				Enabled:         true,
				UpdatedAt:       "2025-09-23T08:05:59.271458Z",
				VersionID:       1111111111113,
			},
			UpdatedAt: "2025-09-23T08:05:59.271458Z",
			VersionID: 1111111111113,
		},
	},
}

func TestFilterByID(t *testing.T) {
	actual := testFloatingIPs.FilterByID("someid").FindOne()

	if actual.ID != "someid" {
		t.Fatal("actual:", actual.ID, "> expected: someid")
	}
}

func TestFilterByName(t *testing.T) {
	actual := testFloatingIPs.FilterByAccessGroupName("testname").FindOne()

	if actual.AccessGroupName != "testname" {
		t.Fatal("actual:", actual.AccessGroupID, ">> expected: testname")
	}
}

func TestFilterFunc(t *testing.T) {
	actual := testFloatingIPs.FilterFunc(func(rfi RecordFloatingIP) bool {
		return rfi.VersionID == 1111111111111
	})

	if len(actual.Objects) != 1 || actual.Objects[0].ID != "someid" {
		t.Fatal("Expected 1 policy with version ID 1111111111111, found:", len(actual.Objects))
	}
}

func TestFindOneWithResults(t *testing.T) {
	result := testFloatingIPs.FilterByID("someid").FindOne()
	if result.ID != "someid" {
		t.Fatal("Expected someid, got:", result.ID)
	}
}

func TestFindOneEmpty(t *testing.T) {
	emptyList := FloatingIPsList{}
	result := emptyList.FindOne()

	if result.ID != "" || result.AccessGroupID != "" {
		t.Fatal("Expected empty FloatingIP, got:", result)
	}
}

func TestFilterByIDNotFound(t *testing.T) {
	actual := testFloatingIPs.FilterByID("nonex")

	if len(actual.Objects) != 0 {
		t.Fatal("Expected 0 policies, found:", len(actual.Objects))
	}
}
