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

// CloudlogService20210330Filter Filter represents the object that associates or excludes resources with a destination. Depending on the type of resource log the
// filter determines if the log should be streamed to the configured destination.
//
// swagger:model cloudlog_service_20210330Filter
type CloudlogService20210330Filter struct {

	// dataplane_audit_filter represents a data plane audit filter.
	DataplaneAuditFilter *LogService20210330DataPlaneAuditFilter `json:"dataplane_audit_filter,omitempty"`

	// organization_filter represents an org level filter.
	OrganizationFilter *LogService20210330OrganizationFilter `json:"organization_filter,omitempty"`
}

// Validate validates this cloudlog service 20210330 filter
func (m *CloudlogService20210330Filter) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *CloudlogService20210330Filter) validateDataplaneAuditFilter(formats strfmt.Registry) error {
	if swag.IsZero(m.DataplaneAuditFilter) { // not required
		return nil
	}

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

	return nil
}

func (m *CloudlogService20210330Filter) validateOrganizationFilter(formats strfmt.Registry) error {
	if swag.IsZero(m.OrganizationFilter) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this cloudlog service 20210330 filter based on the context it is used
func (m *CloudlogService20210330Filter) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *CloudlogService20210330Filter) contextValidateDataplaneAuditFilter(ctx context.Context, formats strfmt.Registry) error {

	if m.DataplaneAuditFilter != nil {

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

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

	return nil
}

func (m *CloudlogService20210330Filter) contextValidateOrganizationFilter(ctx context.Context, formats strfmt.Registry) error {

	if m.OrganizationFilter != nil {

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

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

	return nil
}

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

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