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

// DataflowAuthentication dataflow authentication
//
// swagger:model dataflowAuthentication
type DataflowAuthentication struct {

	// auth type
	AuthType *DataflowKafkaAuthType `json:"auth_type,omitempty"`

	// password
	Password string `json:"password,omitempty"`

	// user name
	UserName string `json:"userName,omitempty"`
}

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

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

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

func (m *DataflowAuthentication) validateAuthType(formats strfmt.Registry) error {
	if swag.IsZero(m.AuthType) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *DataflowAuthentication) contextValidateAuthType(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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

func NewDataFlowAuthentication(authType *DataflowKafkaAuthType, password string, userName string) DataflowAuthentication {
	return DataflowAuthentication{authType, password, userName}
}
