package validator

import (
	"github.com/go-playground/validator/v10"
)

type OrderValidator interface {
	Validate(interface{}) error
}

type OrderValidatorImpl struct {
	validate *validator.Validate
}

func NewOrderValidator() OrderValidator {
	v := validator.New()
	return &OrderValidatorImpl{
		validate: v,
	}
}

func (v *OrderValidatorImpl) Validate(i interface{}) error {
	return v.validate.Struct(i)
}

func (v *OrderValidatorImpl) validateOrderType(fl validator.FieldLevel) bool {
	orderType := fl.Field().String()
	switch orderType {
	case "dine_in", "takeaway", "delivery":
		return true
	default:
		return false
	}
}

func (v *OrderValidatorImpl) validateOrderStatus(fl validator.FieldLevel) bool {
	status := fl.Field().String()
	switch status {
	case "pending", "preparing", "ready", "completed", "cancelled":
		return true
	default:
		return false
	}
}

func (v *OrderValidatorImpl) validatePaymentStatus(fl validator.FieldLevel) bool {
	status := fl.Field().String()
	switch status {
	case "pending", "partially_paid", "completed", "refunded":
		return true
	default:
		return false
	}
}

func (v *OrderValidatorImpl) validatePaymentTransactionStatus(fl validator.FieldLevel) bool {
	status := fl.Field().String()
	switch status {
	case "pending", "completed", "failed", "refunded", "cancelled":
		return true
	default:
		return false
	}
}

func (v *OrderValidatorImpl) validateOrderItemStatus(fl validator.FieldLevel) bool {
	status := fl.Field().String()
	switch status {
	case "pending", "preparing", "ready", "completed", "cancelled":
		return true
	default:
		return false
	}
}
