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

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

// VolumeOnboarding volume onboarding
//
// swagger:model VolumeOnboarding
type VolumeOnboarding struct {
	VolumeOnboardingCommon

	// Indicates the create-time of volume onboarding operation
	// Format: date-time
	CreationTimestamp strfmt.DateTime `json:"creationTimestamp,omitempty"`

	// Indicates the progress of volume onboarding operation
	Progress float64 `json:"progress,omitempty"`

	// results
	Results *VolumeOnboardingResults `json:"results,omitempty"`
}

// UnmarshalJSON unmarshals this object from a JSON structure
func (m *VolumeOnboarding) UnmarshalJSON(raw []byte) error {
	// AO0
	var aO0 VolumeOnboardingCommon
	if err := swag.ReadJSON(raw, &aO0); err != nil {
		return err
	}
	m.VolumeOnboardingCommon = aO0

	// now for regular properties
	var propsVolumeOnboarding struct {
		CreationTimestamp strfmt.DateTime `json:"creationTimestamp,omitempty"`

		Progress float64 `json:"progress,omitempty"`

		Results *VolumeOnboardingResults `json:"results,omitempty"`
	}
	if err := swag.ReadJSON(raw, &propsVolumeOnboarding); err != nil {
		return err
	}
	m.CreationTimestamp = propsVolumeOnboarding.CreationTimestamp

	m.Progress = propsVolumeOnboarding.Progress

	m.Results = propsVolumeOnboarding.Results

	return nil
}

// MarshalJSON marshals this object to a JSON structure
func (m VolumeOnboarding) MarshalJSON() ([]byte, error) {
	_parts := make([][]byte, 0, 1)

	aO0, err := swag.WriteJSON(m.VolumeOnboardingCommon)
	if err != nil {
		return nil, err
	}
	_parts = append(_parts, aO0)

	// now for regular properties
	var propsVolumeOnboarding struct {
		CreationTimestamp strfmt.DateTime `json:"creationTimestamp,omitempty"`

		Progress float64 `json:"progress,omitempty"`

		Results *VolumeOnboardingResults `json:"results,omitempty"`
	}
	propsVolumeOnboarding.CreationTimestamp = m.CreationTimestamp

	propsVolumeOnboarding.Progress = m.Progress

	propsVolumeOnboarding.Results = m.Results

	jsonDataPropsVolumeOnboarding, errVolumeOnboarding := swag.WriteJSON(propsVolumeOnboarding)
	if errVolumeOnboarding != nil {
		return nil, errVolumeOnboarding
	}
	_parts = append(_parts, jsonDataPropsVolumeOnboarding)
	return swag.ConcatJSON(_parts...), nil
}

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

	// validation for a type composition with VolumeOnboardingCommon
	if err := m.VolumeOnboardingCommon.Validate(formats); err != nil {
		res = append(res, err)
	}

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

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

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

func (m *VolumeOnboarding) validateCreationTimestamp(formats strfmt.Registry) error {
	if swag.IsZero(m.CreationTimestamp) { // not required
		return nil
	}

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

	return nil
}

func (m *VolumeOnboarding) validateResults(formats strfmt.Registry) error {
	if swag.IsZero(m.Results) { // not required
		return nil
	}

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

	return nil
}

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

	// validation for a type composition with VolumeOnboardingCommon
	if err := m.VolumeOnboardingCommon.ContextValidate(ctx, formats); err != nil {
		res = append(res, err)
	}

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

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

func (m *VolumeOnboarding) contextValidateResults(ctx context.Context, formats strfmt.Registry) error {

	if m.Results != nil {

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

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

	return nil
}

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

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

// VolumeOnboardingResults volume onboarding results
//
// swagger:model VolumeOnboardingResults
type VolumeOnboardingResults struct {

	// List of volumes which are onboarded successfully
	OnboardedVolumes []string `json:"onboardedVolumes"`

	// volume onboarding failures
	VolumeOnboardingFailures []*VolumeOnboardingFailure `json:"volumeOnboardingFailures"`
}

// Validate validates this volume onboarding results
func (m *VolumeOnboardingResults) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *VolumeOnboardingResults) validateVolumeOnboardingFailures(formats strfmt.Registry) error {
	if swag.IsZero(m.VolumeOnboardingFailures) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

func (m *VolumeOnboardingResults) contextValidateVolumeOnboardingFailures(ctx context.Context, formats strfmt.Registry) error {

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

		if m.VolumeOnboardingFailures[i] != nil {

			if swag.IsZero(m.VolumeOnboardingFailures[i]) { // not required
				return nil
			}

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

	}

	return nil
}

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

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