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

package pipeline_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"
	"github.com/go-openapi/validate"
)

// V2beta1Pipeline v2beta1 pipeline
//
// swagger:model v2beta1Pipeline
type V2beta1Pipeline struct {

	// Output. Creation time of the pipeline.
	// Format: date-time
	CreatedAt strfmt.DateTime `json:"created_at,omitempty"`

	// Optional input field. A short description of the pipeline.
	Description string `json:"description,omitempty"`

	// Required if name is not provided. Pipeline display name provided by user.
	DisplayName string `json:"display_name,omitempty"`

	// In case any error happens retrieving a pipeline field, only pipeline ID,
	// and the error message is returned. Client has the flexibility of choosing
	// how to handle the error. This is especially useful during listing call.
	Error *GooglerpcStatus `json:"error,omitempty"`

	// Required if display_name is not provided. Pipeline name provided by user.
	Name string `json:"name,omitempty"`

	// Input. A namespace this pipeline belongs to.
	// Causes error if user is not authorized to access the specified namespace.
	// If not specified in CreatePipeline, default namespace is used.
	Namespace string `json:"namespace,omitempty"`

	// Output. Unique pipeline ID. Generated by API server.
	PipelineID string `json:"pipeline_id,omitempty"`
}

// Validate validates this v2beta1 pipeline
func (m *V2beta1Pipeline) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *V2beta1Pipeline) validateCreatedAt(formats strfmt.Registry) error {
	if swag.IsZero(m.CreatedAt) { // not required
		return nil
	}

	if err := validate.FormatOf("created_at", "body", "date-time", m.CreatedAt.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *V2beta1Pipeline) validateError(formats strfmt.Registry) error {
	if swag.IsZero(m.Error) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *V2beta1Pipeline) contextValidateError(ctx context.Context, formats strfmt.Registry) error {

	if m.Error != nil {

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

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

	return nil
}

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

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