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

package run_model

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

// APIRunDetail api run detail
//
// swagger:model apiRunDetail
type APIRunDetail struct {

	// pipeline runtime
	PipelineRuntime *APIPipelineRuntime `json:"pipeline_runtime,omitempty"`

	// run
	Run *APIRun `json:"run,omitempty"`
}

// Validate validates this api run detail
func (m *APIRunDetail) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *APIRunDetail) validatePipelineRuntime(formats strfmt.Registry) error {
	if swag.IsZero(m.PipelineRuntime) { // not required
		return nil
	}

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

	return nil
}

func (m *APIRunDetail) validateRun(formats strfmt.Registry) error {
	if swag.IsZero(m.Run) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *APIRunDetail) contextValidatePipelineRuntime(ctx context.Context, formats strfmt.Registry) error {

	if m.PipelineRuntime != nil {

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

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

	return nil
}

func (m *APIRunDetail) contextValidateRun(ctx context.Context, formats strfmt.Registry) error {

	if m.Run != nil {

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

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

	return nil
}

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

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