package service

import (
	"regexp"

	errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
	validation "github.com/go-ozzo/ozzo-validation"
)

const (
	PhoneNumberRegex = "^(0|0098|\\+98)9(0[1-5]|[1 3]\\d|2[0-2]|98)\\d{7}$"
)

type Validator struct{}

func NewValidator() Validator {
	return Validator{}
}

func (v Validator) ValidateSendOtpRequest(req SendOtpRequest) error {
	err := validation.ValidateStruct(&req,
		validation.Field(req.PhoneNumber,
			validation.Required,
			validation.Match(regexp.MustCompile(PhoneNumberRegex)).Error(errmsg.ErrorMsgPhoneNumberIsNotValid),
		))

	return err

}

func (v Validator) ValidateLoginOrRegisterRequest(req LoginOrRegisterRequest) error {
	err := validation.ValidateStruct(&req,
		validation.Field(req.PhoneNumber,
			validation.Required,
			validation.Match(regexp.MustCompile(PhoneNumberRegex)).Error(errmsg.ErrorMsgPhoneNumberIsNotValid)),
		validation.Field(req.VerifyCode,
			validation.Required))

	return err
}
