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

package ops

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

import (
	"context"

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

// OperationOperationAction operation operation action
//
// swagger:model operation.OperationAction
type OperationOperationAction struct {

	// Name is the action name.
	Name string `json:"name,omitempty"`

	// Optional means this action is optional.
	Optional bool `json:"optional,omitempty"`

	// PreferScheduleHour is the default schedule hour, and the schedule time is `now()+hour` when shown on UI.
	PreferScheduleHour int64 `json:"prefer_schedule_hour,omitempty"`

	// prefer start policy
	PreferStartPolicy *OperationOperationActionPreferStartPolicy `json:"prefer_start_policy,omitempty"`
}

// Validate validates this operation operation action
func (m *OperationOperationAction) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *OperationOperationAction) validatePreferStartPolicy(formats strfmt.Registry) error {
	if swag.IsZero(m.PreferStartPolicy) { // not required
		return nil
	}

	if m.PreferStartPolicy != nil {
		if err := m.PreferStartPolicy.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("prefer_start_policy")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("prefer_start_policy")
			}
			return err
		}
	}

	return nil
}

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

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

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

func (m *OperationOperationAction) contextValidatePreferStartPolicy(ctx context.Context, formats strfmt.Registry) error {

	if m.PreferStartPolicy != nil {

		if swag.IsZero(m.PreferStartPolicy) { // not required
			return nil
		}

		if err := m.PreferStartPolicy.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("prefer_start_policy")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("prefer_start_policy")
			}
			return err
		}
	}

	return nil
}

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

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