// Code generated by go-enum DO NOT EDIT.
// Version: -
// Revision: -
// Build Date: -
// Built By: -

package fields

import (
	"database/sql/driver"
	"errors"
	"fmt"
	"strconv"
	"strings"
)

const (
	// OrderStatusPending is a OrderStatus of type Pending.
	OrderStatusPending OrderStatus = iota
	// OrderStatusPaid is a OrderStatus of type Paid.
	OrderStatusPaid
	// OrderStatusRefundSuccess is a OrderStatus of type Refund_success.
	OrderStatusRefundSuccess
	// OrderStatusRefundClosed is a OrderStatus of type Refund_closed.
	OrderStatusRefundClosed
	// OrderStatusRefundProcessing is a OrderStatus of type Refund_processing.
	OrderStatusRefundProcessing
	// OrderStatusRefundAbnormal is a OrderStatus of type Refund_abnormal.
	OrderStatusRefundAbnormal
	// OrderStatusCancelled is a OrderStatus of type Cancelled.
	OrderStatusCancelled
	// OrderStatusCompleted is a OrderStatus of type Completed.
	OrderStatusCompleted
)

var ErrInvalidOrderStatus = fmt.Errorf("not a valid OrderStatus, try [%s]", strings.Join(_OrderStatusNames, ", "))

const _OrderStatusName = "pendingpaidrefund_successrefund_closedrefund_processingrefund_abnormalcancelledcompleted"

var _OrderStatusNames = []string{
	_OrderStatusName[0:7],
	_OrderStatusName[7:11],
	_OrderStatusName[11:25],
	_OrderStatusName[25:38],
	_OrderStatusName[38:55],
	_OrderStatusName[55:70],
	_OrderStatusName[70:79],
	_OrderStatusName[79:88],
}

// OrderStatusNames returns a list of possible string values of OrderStatus.
func OrderStatusNames() []string {
	tmp := make([]string, len(_OrderStatusNames))
	copy(tmp, _OrderStatusNames)
	return tmp
}

// OrderStatusValues returns a list of the values for OrderStatus
func OrderStatusValues() []OrderStatus {
	return []OrderStatus{
		OrderStatusPending,
		OrderStatusPaid,
		OrderStatusRefundSuccess,
		OrderStatusRefundClosed,
		OrderStatusRefundProcessing,
		OrderStatusRefundAbnormal,
		OrderStatusCancelled,
		OrderStatusCompleted,
	}
}

var _OrderStatusMap = map[OrderStatus]string{
	OrderStatusPending:          _OrderStatusName[0:7],
	OrderStatusPaid:             _OrderStatusName[7:11],
	OrderStatusRefundSuccess:    _OrderStatusName[11:25],
	OrderStatusRefundClosed:     _OrderStatusName[25:38],
	OrderStatusRefundProcessing: _OrderStatusName[38:55],
	OrderStatusRefundAbnormal:   _OrderStatusName[55:70],
	OrderStatusCancelled:        _OrderStatusName[70:79],
	OrderStatusCompleted:        _OrderStatusName[79:88],
}

// String implements the Stringer interface.
func (x OrderStatus) String() string {
	if str, ok := _OrderStatusMap[x]; ok {
		return str
	}
	return fmt.Sprintf("OrderStatus(%d)", x)
}

// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x OrderStatus) IsValid() bool {
	_, ok := _OrderStatusMap[x]
	return ok
}

var _OrderStatusValue = map[string]OrderStatus{
	_OrderStatusName[0:7]:   OrderStatusPending,
	_OrderStatusName[7:11]:  OrderStatusPaid,
	_OrderStatusName[11:25]: OrderStatusRefundSuccess,
	_OrderStatusName[25:38]: OrderStatusRefundClosed,
	_OrderStatusName[38:55]: OrderStatusRefundProcessing,
	_OrderStatusName[55:70]: OrderStatusRefundAbnormal,
	_OrderStatusName[70:79]: OrderStatusCancelled,
	_OrderStatusName[79:88]: OrderStatusCompleted,
}

// ParseOrderStatus attempts to convert a string to a OrderStatus.
func ParseOrderStatus(name string) (OrderStatus, error) {
	if x, ok := _OrderStatusValue[name]; ok {
		return x, nil
	}
	return OrderStatus(0), fmt.Errorf("%s is %w", name, ErrInvalidOrderStatus)
}

var errOrderStatusNilPtr = errors.New("value pointer is nil") // one per type for package clashes

// Scan implements the Scanner interface.
func (x *OrderStatus) Scan(value interface{}) (err error) {
	if value == nil {
		*x = OrderStatus(0)
		return
	}

	// A wider range of scannable types.
	// driver.Value values at the top of the list for expediency
	switch v := value.(type) {
	case int64:
		*x = OrderStatus(v)
	case string:
		*x, err = ParseOrderStatus(v)
		if err != nil {
			// try parsing the integer value as a string
			if val, verr := strconv.Atoi(v); verr == nil {
				*x, err = OrderStatus(val), nil
			}
		}
	case []byte:
		*x, err = ParseOrderStatus(string(v))
		if err != nil {
			// try parsing the integer value as a string
			if val, verr := strconv.Atoi(string(v)); verr == nil {
				*x, err = OrderStatus(val), nil
			}
		}
	case OrderStatus:
		*x = v
	case int:
		*x = OrderStatus(v)
	case *OrderStatus:
		if v == nil {
			return errOrderStatusNilPtr
		}
		*x = *v
	case uint:
		*x = OrderStatus(v)
	case uint64:
		*x = OrderStatus(v)
	case *int:
		if v == nil {
			return errOrderStatusNilPtr
		}
		*x = OrderStatus(*v)
	case *int64:
		if v == nil {
			return errOrderStatusNilPtr
		}
		*x = OrderStatus(*v)
	case float64: // json marshals everything as a float64 if it's a number
		*x = OrderStatus(v)
	case *float64: // json marshals everything as a float64 if it's a number
		if v == nil {
			return errOrderStatusNilPtr
		}
		*x = OrderStatus(*v)
	case *uint:
		if v == nil {
			return errOrderStatusNilPtr
		}
		*x = OrderStatus(*v)
	case *uint64:
		if v == nil {
			return errOrderStatusNilPtr
		}
		*x = OrderStatus(*v)
	case *string:
		if v == nil {
			return errOrderStatusNilPtr
		}
		*x, err = ParseOrderStatus(*v)
		if err != nil {
			// try parsing the integer value as a string
			if val, verr := strconv.Atoi(*v); verr == nil {
				*x, err = OrderStatus(val), nil
			}
		}
	}

	return
}

// Value implements the driver Valuer interface.
func (x OrderStatus) Value() (driver.Value, error) {
	return int64(x), nil
}

// Set implements the Golang flag.Value interface func.
func (x *OrderStatus) Set(val string) error {
	v, err := ParseOrderStatus(val)
	*x = v
	return err
}

// Get implements the Golang flag.Getter interface func.
func (x *OrderStatus) Get() interface{} {
	return *x
}

// Type implements the github.com/spf13/pFlag Value interface.
func (x *OrderStatus) Type() string {
	return "OrderStatus"
}

type NullOrderStatus struct {
	OrderStatus OrderStatus
	Valid       bool
}

func NewNullOrderStatus(val interface{}) (x NullOrderStatus) {
	x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
	return
}

// Scan implements the Scanner interface.
func (x *NullOrderStatus) Scan(value interface{}) (err error) {
	if value == nil {
		x.OrderStatus, x.Valid = OrderStatus(0), false
		return
	}

	err = x.OrderStatus.Scan(value)
	x.Valid = (err == nil)
	return
}

// Value implements the driver Valuer interface.
func (x NullOrderStatus) Value() (driver.Value, error) {
	if !x.Valid {
		return nil, nil
	}
	// driver.Value accepts int64 for int values.
	return int64(x.OrderStatus), nil
}

type NullOrderStatusStr struct {
	NullOrderStatus
}

func NewNullOrderStatusStr(val interface{}) (x NullOrderStatusStr) {
	x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
	return
}

// Value implements the driver Valuer interface.
func (x NullOrderStatusStr) Value() (driver.Value, error) {
	if !x.Valid {
		return nil, nil
	}
	return x.OrderStatus.String(), nil
}
