package netobjgroups

import "testing"

var testNetObjGroups = NetObjGroupList{
	Objects: []RecordNetObjGroup{
		{
			AccessGroupID:   "d85d4a08-3216-4240-a8bd-191cd9cc3bf3",
			AccessGroupName: "Test1",
			CreatedAt:       "2025-09-04T13:18:14.412118Z",
			Description:     "test descr",
			ID:              "0b16493b-0a38-4c90-80a0-c19f898f593d",
			Name:            "Test1",
			UpdatedAt:       "2025-10-28T07:28:15.450717Z",
			VersionID:       1761636495441,
			Counters: Counter{
				LogicalPortsCount:     1,
				SecurityPoliciesCount: 2,
				SecurityRulesCount:    0,
			},
		},
		{
			AccessGroupID:   "d85d4a08-3216-4240-a8bd-191cd9cc3bf3",
			AccessGroupName: "Test2",
			CreatedAt:       "2025-09-04T13:18:14.412118Z",
			Description:     "another descr",
			ID:              "0b16493b-0a38-4c90-80a0-c19f898f593e",
			Name:            "Test2",
			UpdatedAt:       "2025-10-28T07:28:15.450717Z",
			VersionID:       1761636495442,
			Counters: Counter{
				LogicalPortsCount:     1,
				SecurityPoliciesCount: 2,
				SecurityRulesCount:    0,
			},
		},
		{
			AccessGroupID:   "d85d4a08-3216-4240-a8bd-191cd9cc3bf3",
			AccessGroupName: "Test3",
			CreatedAt:       "2025-09-04T13:18:14.412118Z",
			Description:     "another descr",
			ID:              "0b16493b-0a38-4c90-80a0-c19f898f593f",
			Name:            "Test3",
			UpdatedAt:       "2025-10-28T07:28:15.450717Z",
			VersionID:       1761636495443,
			Counters: Counter{
				LogicalPortsCount:     1,
				SecurityPoliciesCount: 2,
				SecurityRulesCount:    0,
			},
		},
	},
}

func TestFilterByID(t *testing.T) {
	actual := testNetObjGroups.FilterByID("0b16493b-0a38-4c90-80a0-c19f898f593d").FindOne()

	if actual.ID != "0b16493b-0a38-4c90-80a0-c19f898f593d" {
		t.Fatal("actual:", actual.ID, "> expected: 0b16493b-0a38-4c90-80a0-c19f898f593d")
	}
}

func TestFilterByName(t *testing.T) {
	actual := testNetObjGroups.FilterByName("Test1").FindOne()

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

func TestFilterFunc(t *testing.T) {
	actual := testNetObjGroups.FilterFunc(func(rnog RecordNetObjGroup) bool {
		return rnog.Description == "test descr"
	})

	if len(actual.Objects) != 1 || actual.Objects[0].ID != "0b16493b-0a38-4c90-80a0-c19f898f593d" {
		t.Fatal("Expected 1 policy with description 'Second policy', found:", len(actual.Objects))
	}
}

func TestFindOneWithResults(t *testing.T) {
	result := testNetObjGroups.FilterByID("0b16493b-0a38-4c90-80a0-c19f898f593d").FindOne()
	if result.ID != "0b16493b-0a38-4c90-80a0-c19f898f593d" {
		t.Fatal("Expected 0b16493b-0a38-4c90-80a0-c19f898f593d, got:", result.ID)
	}
}

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

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

func TestFilterByIDNotFound(t *testing.T) {
	actual := testNetObjGroups.FilterByID("0b16493b-0a38-4c90-80a0-c19f898f593n")

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

func TestFilterByDisplayNameNotFound(t *testing.T) {
	actual := testNetObjGroups.FilterByName("Nonexistent Policy")

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