// Code generated by protoc-gen-validate. DO NOT EDIT.
// source: order/v1/order.proto

package v1

import (
	"bytes"
	"errors"
	"fmt"
	"net"
	"net/mail"
	"net/url"
	"regexp"
	"sort"
	"strings"
	"time"
	"unicode/utf8"

	"google.golang.org/protobuf/types/known/anypb"
)

// ensure the imports are used
var (
	_ = bytes.MinRead
	_ = errors.New("")
	_ = fmt.Print
	_ = utf8.UTFMax
	_ = (*regexp.Regexp)(nil)
	_ = (*strings.Reader)(nil)
	_ = net.IPv4len
	_ = time.Duration(0)
	_ = (*url.URL)(nil)
	_ = (*mail.Address)(nil)
	_ = anypb.Any{}
	_ = sort.Sort
)

// Validate checks the field values on CartItem with the rules defined in the
// proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *CartItem) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on CartItem with the rules defined in
// the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in CartItemMultiError, or nil
// if none found.
func (m *CartItem) ValidateAll() error {
	return m.validate(true)
}

func (m *CartItem) validate(all bool) error {
	if m == nil {
		return nil
	}

	var errors []error

	// no validation rules for CartId

	// no validation rules for SkuId

	// no validation rules for SkuPrice

	// no validation rules for SkuNum

	if len(errors) > 0 {
		return CartItemMultiError(errors)
	}

	return nil
}

// CartItemMultiError is an error wrapping multiple validation errors returned
// by CartItem.ValidateAll() if the designated constraints aren't met.
type CartItemMultiError []error

// Error returns a concatenation of all the error messages it wraps.
func (m CartItemMultiError) Error() string {
	var msgs []string
	for _, err := range m {
		msgs = append(msgs, err.Error())
	}
	return strings.Join(msgs, "; ")
}

// AllErrors returns a list of validation violation errors.
func (m CartItemMultiError) AllErrors() []error { return m }

// CartItemValidationError is the validation error returned by
// CartItem.Validate if the designated constraints aren't met.
type CartItemValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}

// Field function returns field value.
func (e CartItemValidationError) Field() string { return e.field }

// Reason function returns reason value.
func (e CartItemValidationError) Reason() string { return e.reason }

// Cause function returns cause value.
func (e CartItemValidationError) Cause() error { return e.cause }

// Key function returns key value.
func (e CartItemValidationError) Key() bool { return e.key }

// ErrorName returns error name.
func (e CartItemValidationError) ErrorName() string { return "CartItemValidationError" }

// Error satisfies the builtin error interface
func (e CartItemValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}

	key := ""
	if e.key {
		key = "key for "
	}

	return fmt.Sprintf(
		"invalid %sCartItem.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = CartItemValidationError{}

var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = CartItemValidationError{}

// Validate checks the field values on OrderRequest with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *OrderRequest) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on OrderRequest with the rules defined
// in the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in OrderRequestMultiError, or
// nil if none found.
func (m *OrderRequest) ValidateAll() error {
	return m.validate(true)
}

func (m *OrderRequest) validate(all bool) error {
	if m == nil {
		return nil
	}

	var errors []error

	// no validation rules for Id

	if m.GetUserId() <= 0 {
		err := OrderRequestValidationError{
			field:  "UserId",
			reason: "value must be greater than 0",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

	if m.GetAddress() <= 0 {
		err := OrderRequestValidationError{
			field:  "Address",
			reason: "value must be greater than 0",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

	for idx, item := range m.GetCartItem() {
		_, _ = idx, item

		if all {
			switch v := interface{}(item).(type) {
			case interface{ ValidateAll() error }:
				if err := v.ValidateAll(); err != nil {
					errors = append(errors, OrderRequestValidationError{
						field:  fmt.Sprintf("CartItem[%v]", idx),
						reason: "embedded message failed validation",
						cause:  err,
					})
				}
			case interface{ Validate() error }:
				if err := v.Validate(); err != nil {
					errors = append(errors, OrderRequestValidationError{
						field:  fmt.Sprintf("CartItem[%v]", idx),
						reason: "embedded message failed validation",
						cause:  err,
					})
				}
			}
		} else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return OrderRequestValidationError{
					field:  fmt.Sprintf("CartItem[%v]", idx),
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}

	}

	if len(errors) > 0 {
		return OrderRequestMultiError(errors)
	}

	return nil
}

// OrderRequestMultiError is an error wrapping multiple validation errors
// returned by OrderRequest.ValidateAll() if the designated constraints aren't met.
type OrderRequestMultiError []error

// Error returns a concatenation of all the error messages it wraps.
func (m OrderRequestMultiError) Error() string {
	var msgs []string
	for _, err := range m {
		msgs = append(msgs, err.Error())
	}
	return strings.Join(msgs, "; ")
}

// AllErrors returns a list of validation violation errors.
func (m OrderRequestMultiError) AllErrors() []error { return m }

// OrderRequestValidationError is the validation error returned by
// OrderRequest.Validate if the designated constraints aren't met.
type OrderRequestValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}

// Field function returns field value.
func (e OrderRequestValidationError) Field() string { return e.field }

// Reason function returns reason value.
func (e OrderRequestValidationError) Reason() string { return e.reason }

// Cause function returns cause value.
func (e OrderRequestValidationError) Cause() error { return e.cause }

// Key function returns key value.
func (e OrderRequestValidationError) Key() bool { return e.key }

// ErrorName returns error name.
func (e OrderRequestValidationError) ErrorName() string { return "OrderRequestValidationError" }

// Error satisfies the builtin error interface
func (e OrderRequestValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}

	key := ""
	if e.key {
		key = "key for "
	}

	return fmt.Sprintf(
		"invalid %sOrderRequest.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = OrderRequestValidationError{}

var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = OrderRequestValidationError{}

// Validate checks the field values on OrderInfoResponse with the rules defined
// in the proto definition for this message. If any rules are violated, the
// first error encountered is returned, or nil if there are no violations.
func (m *OrderInfoResponse) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on OrderInfoResponse with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// OrderInfoResponseMultiError, or nil if none found.
func (m *OrderInfoResponse) ValidateAll() error {
	return m.validate(true)
}

func (m *OrderInfoResponse) validate(all bool) error {
	if m == nil {
		return nil
	}

	var errors []error

	// no validation rules for Id

	// no validation rules for UserId

	// no validation rules for OrderSn

	// no validation rules for PayType

	// no validation rules for Status

	// no validation rules for Post

	// no validation rules for Total

	// no validation rules for Address

	// no validation rules for Name

	// no validation rules for Mobile

	// no validation rules for AddTime

	if len(errors) > 0 {
		return OrderInfoResponseMultiError(errors)
	}

	return nil
}

// OrderInfoResponseMultiError is an error wrapping multiple validation errors
// returned by OrderInfoResponse.ValidateAll() if the designated constraints
// aren't met.
type OrderInfoResponseMultiError []error

// Error returns a concatenation of all the error messages it wraps.
func (m OrderInfoResponseMultiError) Error() string {
	var msgs []string
	for _, err := range m {
		msgs = append(msgs, err.Error())
	}
	return strings.Join(msgs, "; ")
}

// AllErrors returns a list of validation violation errors.
func (m OrderInfoResponseMultiError) AllErrors() []error { return m }

// OrderInfoResponseValidationError is the validation error returned by
// OrderInfoResponse.Validate if the designated constraints aren't met.
type OrderInfoResponseValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}

// Field function returns field value.
func (e OrderInfoResponseValidationError) Field() string { return e.field }

// Reason function returns reason value.
func (e OrderInfoResponseValidationError) Reason() string { return e.reason }

// Cause function returns cause value.
func (e OrderInfoResponseValidationError) Cause() error { return e.cause }

// Key function returns key value.
func (e OrderInfoResponseValidationError) Key() bool { return e.key }

// ErrorName returns error name.
func (e OrderInfoResponseValidationError) ErrorName() string {
	return "OrderInfoResponseValidationError"
}

// Error satisfies the builtin error interface
func (e OrderInfoResponseValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}

	key := ""
	if e.key {
		key = "key for "
	}

	return fmt.Sprintf(
		"invalid %sOrderInfoResponse.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = OrderInfoResponseValidationError{}

var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = OrderInfoResponseValidationError{}
