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

// Nodeinfo Nodeinfo represents a version 2.1 or version 2.0 nodeinfo schema.
//
// See: https://nodeinfo.diaspora.software/schema.html
//
// swagger:model Nodeinfo
type Nodeinfo struct {

	// Free form key value pairs for software specific values. Clients should not rely on any specific key present.
	Metadata map[string]interface{} `json:"metadata,omitempty"`

	// Whether this server allows open self-registration.
	// Example: false
	OpenRegistrations bool `json:"openRegistrations,omitempty"`

	// The protocols supported on this server.
	Protocols []string `json:"protocols"`

	// The schema version
	// Example: 2.0
	Version string `json:"version,omitempty"`

	// services
	Services *NodeInfoServices `json:"services,omitempty"`

	// software
	Software *NodeInfoSoftware `json:"software,omitempty"`

	// usage
	Usage *NodeInfoUsage `json:"usage,omitempty"`
}

// Validate validates this nodeinfo
func (m *Nodeinfo) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *Nodeinfo) validateServices(formats strfmt.Registry) error {
	if swag.IsZero(m.Services) { // not required
		return nil
	}

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

	return nil
}

func (m *Nodeinfo) validateSoftware(formats strfmt.Registry) error {
	if swag.IsZero(m.Software) { // not required
		return nil
	}

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

	return nil
}

func (m *Nodeinfo) validateUsage(formats strfmt.Registry) error {
	if swag.IsZero(m.Usage) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

func (m *Nodeinfo) contextValidateServices(ctx context.Context, formats strfmt.Registry) error {

	if m.Services != nil {

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

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

	return nil
}

func (m *Nodeinfo) contextValidateSoftware(ctx context.Context, formats strfmt.Registry) error {

	if m.Software != nil {

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

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

	return nil
}

func (m *Nodeinfo) contextValidateUsage(ctx context.Context, formats strfmt.Registry) error {

	if m.Usage != nil {

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

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

	return nil
}

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

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