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

// SchemasObject schemas object
//
// swagger:model SchemasObject
type SchemasObject struct {

	// service binding
	ServiceBinding *ServiceBindingSchemaObject `json:"service_binding,omitempty"`

	// service instance
	ServiceInstance *ServiceInstanceSchemaObject `json:"service_instance,omitempty"`
}

// Validate validates this schemas object
func (m *SchemasObject) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *SchemasObject) validateServiceBinding(formats strfmt.Registry) error {
	if swag.IsZero(m.ServiceBinding) { // not required
		return nil
	}

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

	return nil
}

func (m *SchemasObject) validateServiceInstance(formats strfmt.Registry) error {
	if swag.IsZero(m.ServiceInstance) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (m *SchemasObject) contextValidateServiceBinding(ctx context.Context, formats strfmt.Registry) error {

	if m.ServiceBinding != nil {

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

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

	return nil
}

func (m *SchemasObject) contextValidateServiceInstance(ctx context.Context, formats strfmt.Registry) error {

	if m.ServiceInstance != nil {

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

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

	return nil
}

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

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