package benefactorvalidator

import (
	"testing"

	benefactoreparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor"
	errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
	"github.com/stretchr/testify/assert"
)

func TestValidator_ValidateLoginRegisterRequest(t *testing.T) {
	mockRepository := NewMockRepository(t)
	validator := New(mockRepository)
	validPhoneNumber := "09123456789"

	t.Run("Valid request", func(t *testing.T) {
		req := benefactoreparam.LoginOrRegisterRequest{
			PhoneNumber: validPhoneNumber,
		}

		fieldErrors, err := validator.ValidateLoginRegisterRequest(req)
		assert.NoError(t, err)
		assert.Nil(t, fieldErrors)
	})

	t.Run("Empty phone number", func(t *testing.T) {
		req := benefactoreparam.LoginOrRegisterRequest{
			PhoneNumber: "",
		}

		fieldErrors, err := validator.ValidateLoginRegisterRequest(req)
		assert.Error(t, err)
		assert.NotNil(t, fieldErrors)
		assert.Contains(t, fieldErrors, "phone_number")
	})

	t.Run("Invalid phone number format", func(t *testing.T) {
		req := benefactoreparam.LoginOrRegisterRequest{
			PhoneNumber: "12345",
		}

		fieldErrors, err := validator.ValidateLoginRegisterRequest(req)
		assert.Error(t, err)
		assert.NotNil(t, fieldErrors)
		assert.Equal(t, errmsg.ErrorMsgPhoneNumberIsNotValid, fieldErrors["phone_number"])
	})
}
