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

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

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

	// New account registrations require admin approval.
	ApprovalRequired bool `json:"approval_required,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"`

	// An email address that may be used for inquiries.
	// Example: admin@example.org
	Email string `json:"email,omitempty"`

	// Invites are enabled on this instance.
	InvitesEnabled bool `json:"invites_enabled,omitempty"`

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

	// Maximum allowed length of a post on this instance, in characters.
	//
	// This is provided for compatibility with Tusky and other apps.
	// Example: 5000
	MaxTootChars uint64 `json:"max_toot_chars,omitempty"`

	// New account registrations are enabled on this instance.
	Registrations bool `json:"registrations,omitempty"`

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

	// A shorter description of the instance.
	//
	// Should be HTML formatted, but might be plaintext.
	//
	// This should be displayed on the instance splash/landing page.
	ShortDescription string `json:"short_description,omitempty"`

	// Raw (unparsed) version of short description.
	ShortDescriptionText string `json:"short_description_text,omitempty"`

	// Statistics about the instance: number of posts, accounts, etc.
	// Values are pointers because we don't want to skip 0 values when
	// rendering stats via web templates.
	Stats map[string]int64 `json:"stats,omitempty"`

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

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

	// URL of the instance avatar/banner image.
	// Example: https://example.org/files/instance/thumbnail.jpeg
	Thumbnail string `json:"thumbnail,omitempty"`

	// Description of the instance thumbnail.
	// Example: picture of a cute lil' friendly sloth
	ThumbnailDescription string `json:"thumbnail_description,omitempty"`

	// URL of the static instance avatar/banner image.
	// Example: https://example.org/files/instance/static/thumbnail.webp
	ThumbnailStatic string `json:"thumbnail_static,omitempty"`

	// MIME type of the static instance thumbnail.
	// Example: image/webp
	ThumbnailStaticType string `json:"thumbnail_static_type,omitempty"`

	// MIME type of the instance thumbnail.
	// Example: image/png
	ThumbnailType string `json:"thumbnail_type,omitempty"`

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

	// The URI of the instance.
	// Example: https://gts.example.org
	URI string `json:"uri,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 *InstanceV1Configuration `json:"configuration,omitempty"`

	// contact account
	ContactAccount *Account `json:"contact_account,omitempty"`

	// urls
	Urls *InstanceV1URLs `json:"urls,omitempty"`
}

// Validate validates this instance v1
func (m *InstanceV1) 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.validateContactAccount(formats); err != nil {
		res = append(res, err)
	}

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

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

func (m *InstanceV1) 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 *InstanceV1) 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 *InstanceV1) validateContactAccount(formats strfmt.Registry) error {
	if swag.IsZero(m.ContactAccount) { // not required
		return nil
	}

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

	return nil
}

func (m *InstanceV1) validateUrls(formats strfmt.Registry) error {
	if swag.IsZero(m.Urls) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this instance v1 based on the context it is used
func (m *InstanceV1) 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.contextValidateContactAccount(ctx, formats); err != nil {
		res = append(res, err)
	}

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

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

func (m *InstanceV1) 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 *InstanceV1) 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 *InstanceV1) contextValidateContactAccount(ctx context.Context, formats strfmt.Registry) error {

	if m.ContactAccount != nil {

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

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

	return nil
}

func (m *InstanceV1) contextValidateUrls(ctx context.Context, formats strfmt.Registry) error {

	if m.Urls != nil {

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

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

	return nil
}

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

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