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

// DataflowDWRConnection dataflow d w r connection
//
// swagger:model dataflowDWRConnection
type DataflowDWRConnection struct {

	// bigquery
	Bigquery *DataflowDWRConnectionBigQuery `json:"bigquery,omitempty"`

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

	// redshift
	Redshift *DataflowDWRConnectionRedshift `json:"redshift,omitempty"`

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

// Validate validates this dataflow d w r connection
func (m *DataflowDWRConnection) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *DataflowDWRConnection) validateBigquery(formats strfmt.Registry) error {
	if swag.IsZero(m.Bigquery) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowDWRConnection) 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 *DataflowDWRConnection) validateRedshift(formats strfmt.Registry) error {
	if swag.IsZero(m.Redshift) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowDWRConnection) validateSnowflake(formats strfmt.Registry) error {
	if swag.IsZero(m.Snowflake) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this dataflow d w r connection based on the context it is used
func (m *DataflowDWRConnection) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *DataflowDWRConnection) contextValidateBigquery(ctx context.Context, formats strfmt.Registry) error {

	if m.Bigquery != nil {

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

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

	return nil
}

func (m *DataflowDWRConnection) 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 *DataflowDWRConnection) contextValidateRedshift(ctx context.Context, formats strfmt.Registry) error {

	if m.Redshift != nil {

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

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

	return nil
}

func (m *DataflowDWRConnection) contextValidateSnowflake(ctx context.Context, formats strfmt.Registry) error {

	if m.Snowflake != nil {

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

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

	return nil
}

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

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