package utils

import (
	"reflect"
	"testing"
)

func TestPaginateStringSlice(t *testing.T) {
	// Define example string slice
	strSlice := []string{"apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "kiwi", "lemon", "mango"}
	emptySlice := []string{}
	// Define test cases
	testCases := []struct {
		name      string
		slice     []string
		pageSize  int
		page      int
		wantSlice []string
	}{
		{
			name:      "paginate string slice - page 1",
			slice:     strSlice,
			pageSize:  4,
			page:      1,
			wantSlice: []string{"apple", "banana", "cherry", "date"},
		},
		{
			name:      "paginate string slice - page 2",
			slice:     strSlice,
			pageSize:  4,
			page:      2,
			wantSlice: []string{"elderberry", "fig", "grape", "honeydew"},
		},
		{
			name:      "paginate string slice - page 3",
			slice:     strSlice,
			pageSize:  4,
			page:      3,
			wantSlice: []string{"kiwi", "lemon", "mango"},
		},
		{
			name:      "paginate string slice - page 4(empty)",
			slice:     strSlice,
			pageSize:  4,
			page:      4,
			wantSlice: []string{},
		},
		{
			name:      "empty slice",
			slice:     emptySlice,
			pageSize:  4,
			page:      1,
			wantSlice: []string{},
		},
	}

	// Iterate over test cases
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			// Call paginateSlice function with test case parameters
			gotSlice := PaginateSlice(tc.slice, tc.pageSize, tc.page)

			// Ensure that the returned slice matches the expected slice
			if !reflect.DeepEqual(gotSlice, tc.wantSlice) {
				t.Errorf("paginateSlice() got %v, want %v", gotSlice, tc.wantSlice)
			}
		})
	}
}

func TestPaginateIntSlice(t *testing.T) {
	// Define example int slice
	intSlice := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

	// Define test cases
	testCases := []struct {
		name      string
		slice     []int
		pageSize  int
		page      int
		wantSlice []int
	}{
		{
			name:      "paginate integer slice - page 1",
			slice:     intSlice,
			pageSize:  3,
			page:      1,
			wantSlice: []int{1, 2, 3},
		},
		{
			name:      "paginate integer slice - page 2",
			slice:     intSlice,
			pageSize:  3,
			page:      2,
			wantSlice: []int{4, 5, 6},
		},
	}

	// Iterate over test cases
	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			// Call paginateSlice function with test case parameters
			gotSlice := PaginateSlice(tc.slice, tc.pageSize, tc.page)

			// Ensure that the returned slice matches the expected slice
			if !reflect.DeepEqual(gotSlice, tc.wantSlice) {
				t.Errorf("paginateSlice() got %v, want %v", gotSlice, tc.wantSlice)
			}
		})
	}
}
