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

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// InstanceV2 InstanceV2 models information about this instance.
//
// swagger:model InstanceV2
type InstanceV2 struct {

	// The domain of accounts on this instance.
	// This will not necessarily be the same as
	// domain.
	// Example: example.org
	AccountDomain string `json:"account_domain,omitempty"`

	// Whether or not instance is running in DEBUG mode. Omitted if false.
	Debug bool `json:"debug,omitempty"`

	// Description of the instance.
	//
	// Should be HTML formatted, but might be plaintext.
	//
	// This should be displayed on the 'about' page for an instance.
	Description string `json:"description,omitempty"`

	// Raw (unparsed) version of description.
	DescriptionText string `json:"description_text,omitempty"`

	// The domain of the instance.
	// Example: gts.example.org
	Domain string `json:"domain,omitempty"`

	// Primary languages of the instance + moderators/admins.
	// Example: ["en"]
	Languages []string `json:"languages"`

	// An itemized list of rules for this instance.
	Rules []*InstanceRule `json:"rules"`

	// The URL for the source code of the software running on this instance, in keeping with AGPL license requirements.
	// Example: https://github.com/superseriousbusiness/gotosocial
	SourceURL string `json:"source_url,omitempty"`

	// Terms and conditions for accounts on this instance.
	Terms string `json:"terms,omitempty"`

	// Raw (unparsed) version of terms.
	TermsText string `json:"terms_text,omitempty"`

	// The title of the instance.
	// Example: GoToSocial Example Instance
	Title string `json:"title,omitempty"`

	// The version of GoToSocial installed on the instance.
	//
	// This will contain at least a semantic version number.
	//
	// It may also contain, after a space, the short git commit ID of the running software.
	// Example: 0.1.1 cb85f65
	Version string `json:"version,omitempty"`

	// configuration
	Configuration *InstanceV2Configuration `json:"configuration,omitempty"`

	// contact
	Contact *InstanceV2Contact `json:"contact,omitempty"`

	// registrations
	Registrations *InstanceV2Registrations `json:"registrations,omitempty"`

	// thumbnail
	Thumbnail *InstanceV2Thumbnail `json:"thumbnail,omitempty"`

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

// Validate validates this instance v2
func (m *InstanceV2) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

	if err := m.validateThumbnail(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 *InstanceV2) validateRules(formats strfmt.Registry) error {
	if swag.IsZero(m.Rules) { // not required
		return nil
	}

	for i := 0; i < len(m.Rules); i++ {
		if swag.IsZero(m.Rules[i]) { // not required
			continue
		}

		if m.Rules[i] != nil {
			if err := m.Rules[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("rules" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("rules" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *InstanceV2) validateConfiguration(formats strfmt.Registry) error {
	if swag.IsZero(m.Configuration) { // not required
		return nil
	}

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

	return nil
}

func (m *InstanceV2) validateContact(formats strfmt.Registry) error {
	if swag.IsZero(m.Contact) { // not required
		return nil
	}

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

	return nil
}

func (m *InstanceV2) validateRegistrations(formats strfmt.Registry) error {
	if swag.IsZero(m.Registrations) { // not required
		return nil
	}

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

	return nil
}

func (m *InstanceV2) validateThumbnail(formats strfmt.Registry) error {
	if swag.IsZero(m.Thumbnail) { // not required
		return nil
	}

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

	return nil
}

func (m *InstanceV2) 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 instance v2 based on the context it is used
func (m *InstanceV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

	if err := m.contextValidateThumbnail(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 *InstanceV2) contextValidateRules(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Rules); i++ {

		if m.Rules[i] != nil {

			if swag.IsZero(m.Rules[i]) { // not required
				return nil
			}

			if err := m.Rules[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("rules" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("rules" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *InstanceV2) contextValidateConfiguration(ctx context.Context, formats strfmt.Registry) error {

	if m.Configuration != nil {

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

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

	return nil
}

func (m *InstanceV2) contextValidateContact(ctx context.Context, formats strfmt.Registry) error {

	if m.Contact != nil {

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

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

	return nil
}

func (m *InstanceV2) contextValidateRegistrations(ctx context.Context, formats strfmt.Registry) error {

	if m.Registrations != nil {

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

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

	return nil
}

func (m *InstanceV2) contextValidateThumbnail(ctx context.Context, formats strfmt.Registry) error {

	if m.Thumbnail != nil {

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

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

	return nil
}

func (m *InstanceV2) 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 *InstanceV2) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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