// 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"
	"strconv"

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

// Steps steps
//
// swagger:model steps
type Steps struct {

	// instructions
	Instructions []*Step `json:"instructions"`

	// next instruction seconds
	NextInstructionSeconds int64 `json:"next_instruction_seconds,omitempty"`

	// What to do after finishing to run step instructions
	// Enum: [exit continue]
	PostStepAction *string `json:"post_step_action,omitempty"`
}

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

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

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

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

func (m *Steps) validateInstructions(formats strfmt.Registry) error {
	if swag.IsZero(m.Instructions) { // not required
		return nil
	}

	for i := 0; i < len(m.Instructions); i++ {
		if swag.IsZero(m.Instructions[i]) { // not required
			continue
		}

		if m.Instructions[i] != nil {
			if err := m.Instructions[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("instructions" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("instructions" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

var stepsTypePostStepActionPropEnum []interface{}

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

const (

	// StepsPostStepActionExit captures enum value "exit"
	StepsPostStepActionExit string = "exit"

	// StepsPostStepActionContinue captures enum value "continue"
	StepsPostStepActionContinue string = "continue"
)

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

func (m *Steps) validatePostStepAction(formats strfmt.Registry) error {
	if swag.IsZero(m.PostStepAction) { // not required
		return nil
	}

	// value enum
	if err := m.validatePostStepActionEnum("post_step_action", "body", *m.PostStepAction); err != nil {
		return err
	}

	return nil
}

// ContextValidate validate this steps based on the context it is used
func (m *Steps) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *Steps) contextValidateInstructions(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Instructions); i++ {

		if m.Instructions[i] != nil {
			if err := m.Instructions[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("instructions" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("instructions" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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