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

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

// ClonedVolumeDetail cloned volume detail
//
// swagger:model ClonedVolumeDetail
type ClonedVolumeDetail struct {

	// clone
	// Required: true
	Clone *VolumeInfo `json:"clone"`

	// source
	// Required: true
	Source *VolumeInfo `json:"source"`
}

// Validate validates this cloned volume detail
func (m *ClonedVolumeDetail) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *ClonedVolumeDetail) validateClone(formats strfmt.Registry) error {

	if err := validate.Required("clone", "body", m.Clone); err != nil {
		return err
	}

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

	return nil
}

func (m *ClonedVolumeDetail) validateSource(formats strfmt.Registry) error {

	if err := validate.Required("source", "body", m.Source); err != nil {
		return err
	}

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

	return nil
}

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

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

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

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

func (m *ClonedVolumeDetail) contextValidateClone(ctx context.Context, formats strfmt.Registry) error {

	if m.Clone != nil {

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

	return nil
}

func (m *ClonedVolumeDetail) contextValidateSource(ctx context.Context, formats strfmt.Registry) error {

	if m.Source != nil {

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

	return nil
}

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

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