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

// APIInfluxDbIntegration api influx db integration
//
// swagger:model apiInfluxDbIntegration
type APIInfluxDbIntegration struct {

	// Application ID (UUID).
	ApplicationID string `json:"applicationId,omitempty"`

	// Bucket. (InfluxDb v2)
	Bucket string `json:"bucket,omitempty"`

	// InfluxDb database name. (InfluxDb v1)
	Db string `json:"db,omitempty"`

	// InfluxDb API write endpoint (e.g. http://localhost:8086/write).
	Endpoint string `json:"endpoint,omitempty"`

	// Organization. (InfluxDb v2)
	Organization string `json:"organization,omitempty"`

	// InfluxDb password. (InfluxDb v1)
	Password string `json:"password,omitempty"`

	// InfluxDb timestamp precision (InfluxDb v1).
	Precision *APIInfluxDbPrecision `json:"precision,omitempty"`

	// InfluxDb retention policy name. (InfluxDb v1)
	RetentionPolicyName string `json:"retentionPolicyName,omitempty"`

	// Token. (InfluxDb v2)
	Token string `json:"token,omitempty"`

	// InfluxDb username. (InfluxDb v1)
	Username string `json:"username,omitempty"`

	// InfluxDb version.
	Version *APIInfluxDbVersion `json:"version,omitempty"`
}

// Validate validates this api influx db integration
func (m *APIInfluxDbIntegration) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *APIInfluxDbIntegration) validatePrecision(formats strfmt.Registry) error {
	if swag.IsZero(m.Precision) { // not required
		return nil
	}

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

	return nil
}

func (m *APIInfluxDbIntegration) validateVersion(formats strfmt.Registry) error {
	if swag.IsZero(m.Version) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this api influx db integration based on the context it is used
func (m *APIInfluxDbIntegration) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *APIInfluxDbIntegration) contextValidatePrecision(ctx context.Context, formats strfmt.Registry) error {

	if m.Precision != nil {

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

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

	return nil
}

func (m *APIInfluxDbIntegration) contextValidateVersion(ctx context.Context, formats strfmt.Registry) error {

	if m.Version != nil {

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

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

	return nil
}

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

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