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

// DataflowMySQLInfo dataflow my SQL info
//
// swagger:model dataflowMySQLInfo
type DataflowMySQLInfo struct {

	// connection
	Connection *DataflowConnection `json:"connection,omitempty"`

	// privatelink info
	PrivatelinkInfo *DataflowPrivatelinkInfo `json:"privatelink_info,omitempty"`

	// start position
	StartPosition *DataflowStartPosition `json:"start_position,omitempty"`

	// table config
	TableConfig *DataflowTableConfig `json:"table_config,omitempty"`
}

// Validate validates this dataflow my SQL info
func (m *DataflowMySQLInfo) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *DataflowMySQLInfo) validateConnection(formats strfmt.Registry) error {
	if swag.IsZero(m.Connection) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowMySQLInfo) validatePrivatelinkInfo(formats strfmt.Registry) error {
	if swag.IsZero(m.PrivatelinkInfo) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowMySQLInfo) validateStartPosition(formats strfmt.Registry) error {
	if swag.IsZero(m.StartPosition) { // not required
		return nil
	}

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

	return nil
}

func (m *DataflowMySQLInfo) validateTableConfig(formats strfmt.Registry) error {
	if swag.IsZero(m.TableConfig) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this dataflow my SQL info based on the context it is used
func (m *DataflowMySQLInfo) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *DataflowMySQLInfo) contextValidateConnection(ctx context.Context, formats strfmt.Registry) error {

	if m.Connection != nil {

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

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

	return nil
}

func (m *DataflowMySQLInfo) contextValidatePrivatelinkInfo(ctx context.Context, formats strfmt.Registry) error {

	if m.PrivatelinkInfo != nil {

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

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

	return nil
}

func (m *DataflowMySQLInfo) contextValidateStartPosition(ctx context.Context, formats strfmt.Registry) error {

	if m.StartPosition != nil {

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

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

	return nil
}

func (m *DataflowMySQLInfo) contextValidateTableConfig(ctx context.Context, formats strfmt.Registry) error {

	if m.TableConfig != nil {

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

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

	return nil
}

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

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