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

// DataflowConnector dataflow connector
//
// swagger:model dataflowConnector
type DataflowConnector struct {

	// connector id
	// Required: true
	ConnectorID *string `json:"connector_id"`

	// connector type
	// Required: true
	ConnectorType *DataflowConnectorType `json:"connector_type"`

	// error
	Error string `json:"error,omitempty"`

	// status
	// Required: true
	Status *DataflowConnectorStatus `json:"status"`

	// topic
	Topic string `json:"topic,omitempty"`

	// url
	// Required: true
	URL *string `json:"url"`

	// user
	User string `json:"user,omitempty"`
}

// Validate validates this dataflow connector
func (m *DataflowConnector) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *DataflowConnector) validateConnectorID(formats strfmt.Registry) error {

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

	return nil
}

func (m *DataflowConnector) validateConnectorType(formats strfmt.Registry) error {

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

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

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

	return nil
}

func (m *DataflowConnector) validateStatus(formats strfmt.Registry) error {

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

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

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

	return nil
}

func (m *DataflowConnector) validateURL(formats strfmt.Registry) error {

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

	return nil
}

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

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

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

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

func (m *DataflowConnector) contextValidateConnectorType(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *DataflowConnector) contextValidateStatus(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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