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

// Source Source represents display or publishing preferences of user's own account.
//
// Returned as an additional entity when verifying and updated credentials, as an attribute of Account.
//
// swagger:model Source
type Source struct {

	// This account is aliased to / also known as accounts at the
	// given ActivityPub URIs. To set this, use `/api/v1/accounts/alias`.
	//
	// Omitted from json if empty / not set.
	AlsoKnownAsURIs []string `json:"also_known_as_uris"`

	// Metadata about the account.
	Fields []*Field `json:"fields"`

	// The number of pending follow requests.
	FollowRequestsCount int64 `json:"follow_requests_count,omitempty"`

	// The default posting language for new statuses.
	Language string `json:"language,omitempty"`

	// Profile bio.
	Note string `json:"note,omitempty"`

	// The default post privacy to be used for new statuses.
	// public = Public post
	// unlisted = Unlisted post
	// private = Followers-only post
	// direct = Direct post
	Privacy string `json:"privacy,omitempty"`

	// Whether new statuses should be marked sensitive by default.
	Sensitive bool `json:"sensitive,omitempty"`

	// The default posting content type for new statuses.
	StatusContentType string `json:"status_content_type,omitempty"`
}

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

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

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

func (m *Source) validateFields(formats strfmt.Registry) error {
	if swag.IsZero(m.Fields) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

func (m *Source) contextValidateFields(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Fields[i] != nil {

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

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

	}

	return nil
}

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

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