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

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

// DataflowDumplingObjectStore dataflow dumpling object store
//
// swagger:model dataflowDumplingObjectStore
type DataflowDumplingObjectStore struct {

	// gcs
	Gcs *DataflowObjectStoreGCS `json:"gcs,omitempty"`

	// kind
	// Required: true
	Kind *DataflowDumplingObjectStoreKind `json:"kind"`

	// Note: We are not using oneof, because the generated go code does not support
	// checking the variant type.
	S3 *DataflowObjectStoreS3 `json:"s3,omitempty"`
}

// Validate validates this dataflow dumpling object store
func (m *DataflowDumplingObjectStore) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *DataflowDumplingObjectStore) validateGcs(formats strfmt.Registry) error {
	if swag.IsZero(m.Gcs) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowDumplingObjectStore) validateKind(formats strfmt.Registry) error {

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

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

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

	return nil
}

func (m *DataflowDumplingObjectStore) validateS3(formats strfmt.Registry) error {
	if swag.IsZero(m.S3) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this dataflow dumpling object store based on the context it is used
func (m *DataflowDumplingObjectStore) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *DataflowDumplingObjectStore) contextValidateGcs(ctx context.Context, formats strfmt.Registry) error {

	if m.Gcs != nil {

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

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

	return nil
}

func (m *DataflowDumplingObjectStore) contextValidateKind(ctx context.Context, formats strfmt.Registry) error {

	if m.Kind != nil {

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

	return nil
}

func (m *DataflowDumplingObjectStore) contextValidateS3(ctx context.Context, formats strfmt.Registry) error {

	if m.S3 != nil {

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

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

	return nil
}

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

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