package benefactorkindboxvalidator

import (
	"testing"

	params "git.gocasts.ir/ebhomengo/niki/param"
	param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box"
	"github.com/stretchr/testify/assert"
)

func TestValidator_ValidateGetAll(t *testing.T) {
	mockRepository := NewMockRepository(t)
	mockAddressSvc := NewMockAddressSvc(t)
	mockReferTimeSvc := NewMockReferTimeSvc(t)
	validator := New(mockRepository, mockAddressSvc, mockReferTimeSvc)

	t.Run("Successful validation", func(t *testing.T) {
		req := param.KindBoxGetAllRequest{
			Pagination: params.PaginationRequest{},
			Sort: params.SortRequest{
				Field:     "id",
				Direction: "asc",
			},
			Filter: map[string]any{"id": 1},
		}

		fieldErrors, err := validator.ValidateGetAll(req)

		assert.NoError(t, err)
		assert.Nil(t, fieldErrors)
	})

	t.Run("Invalid sort field", func(t *testing.T) {
		req := param.KindBoxGetAllRequest{
			Pagination: params.PaginationRequest{},
			Sort: params.SortRequest{
				Field:     "invalid",
				Direction: "asc",
			},
			Filter: map[string]any{"id": 1},
		}

		fieldErrors, err := validator.ValidateGetAll(req)

		assert.Error(t, err)
		assert.NotNil(t, fieldErrors)
		assert.Contains(t, fieldErrors, "Sort")
	})

	t.Run("Invalid sort direction", func(t *testing.T) {
		req := param.KindBoxGetAllRequest{
			Pagination: params.PaginationRequest{},
			Sort: params.SortRequest{
				Field:     "id",
				Direction: "invalid",
			},
			Filter: map[string]any{"id": 1},
		}

		fieldErrors, err := validator.ValidateGetAll(req)

		assert.Error(t, err)
		assert.NotNil(t, fieldErrors)
		assert.Contains(t, fieldErrors, "Sort")
	})

	t.Run("Invalid filter", func(t *testing.T) {
		req := param.KindBoxGetAllRequest{
			Pagination: params.PaginationRequest{},
			Sort: params.SortRequest{
				Field:     "id",
				Direction: "desc",
			},
			Filter: map[string]any{"invalid": 1},
		}

		fieldErrors, err := validator.ValidateGetAll(req)

		assert.Error(t, err)
		assert.NotNil(t, fieldErrors)
		assert.Contains(t, fieldErrors, "Filter")
	})
}
