package zone

import "testing"

var zones = ListZones{
	Data: []ItemZone{

		{
			ID:          2,
			GUID:        0,
			GID:         0,
			Name:        "System Config",
			Description: "",
			Deletable:   true,
			Status:      "LOCKED",
			CreatedTime: 1640995200, // 2022-01-01
			UpdatedTime: 1640995200,
			NodeIDs:     nil,
		},
		{
			ID:          5,
			GUID:        5500,
			GID:         6600,
			Name:        "ssss Nodes",
			Description: " infrastructure",
			Deletable:   true,
			Status:      "DISABLED",
			CreatedTime: 1577836800, // 2020-01-01
			UpdatedTime: 1580515200, // 2020-02-01
			NodeIDs:     []uint64{777, 888, 999},
		},
		{
			ID:          10,
			GUID:        5500,
			GID:         6600,
			Name:        "node",
			Description: "infrastructure",
			Deletable:   true,
			Status:      "DISABLED",
			CreatedTime: 1577836800,
			UpdatedTime: 1580515200,
			NodeIDs:     []uint64{777, 888, 999},
		},
	},
}

func TestFilterByID(t *testing.T) {
	actual := zones.FilterByID(10).FindOne()

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

func TestFilterByName(t *testing.T) {
	name := "node"
	actual := zones.FilterByName(name).FindOne()

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

func TestFilterByStatus(t *testing.T) {
	actual := zones.FilterByStatus("DISABLED")

	if len(actual.Data) != 2 {
		t.Fatal("expected 2 found, actual: ", len(actual.Data))
	}

	for _, item := range actual.Data {
		if item.Status != "DISABLED" {
			t.Fatal("expected Status 'DISABLED', found: ", item.Status)
		}
	}
}

func TestFilterFunc(t *testing.T) {
	actual := zones.FilterFunc(func(ien ItemZone) bool {
		return ien.Deletable == true
	})

	if len(actual.Data) != 3 {
		t.Fatal("expected 3 elements, found: ", len(actual.Data))
	}
}
