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_ValidateSendOtpRequest(t *testing.T) {
	validator := New()
	validPhoneNumber := "09123456789"

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

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

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

		fieldErrors, err := validator.ValidateSendOtpRequest(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.SendOtpRequest{
			PhoneNumber: "12345",
		}

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