// Code generated by go-swagger; DO NOT EDIT.

package models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"
	"encoding/json"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"
)

// Order order
//
// swagger:model order
type Order struct {

	// direction
	// Required: true
	// Enum: ["ASC","DESC"]
	Direction string `json:"direction"`

	// field
	// Required: true
	// Min Length: 1
	Field string `json:"field"`
}

// Validate validates this order
func (m *Order) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateDirection(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validateField(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

var orderTypeDirectionPropEnum []interface{}

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["ASC","DESC"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		orderTypeDirectionPropEnum = append(orderTypeDirectionPropEnum, v)
	}
}

const (

	// OrderDirectionASC captures enum value "ASC"
	OrderDirectionASC string = "ASC"

	// OrderDirectionDESC captures enum value "DESC"
	OrderDirectionDESC string = "DESC"
)

// prop value enum
func (m *Order) validateDirectionEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, orderTypeDirectionPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (m *Order) validateDirection(formats strfmt.Registry) error {

	if err := validate.RequiredString("direction", "body", m.Direction); err != nil {
		return err
	}

	// value enum
	if err := m.validateDirectionEnum("direction", "body", m.Direction); err != nil {
		return err
	}

	return nil
}

func (m *Order) validateField(formats strfmt.Registry) error {

	if err := validate.RequiredString("field", "body", m.Field); err != nil {
		return err
	}

	if err := validate.MinLength("field", "body", m.Field, 1); err != nil {
		return err
	}

	return nil
}

// ContextValidate validates this order based on context it is used
func (m *Order) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

// MarshalBinary interface implementation
func (m *Order) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *Order) UnmarshalBinary(b []byte) error {
	var res Order
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
