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

// StatusEdit StatusEdit represents one historical revision of a status, containing
// partial information about the state of the status at that revision.
//
// swagger:model StatusEdit
type StatusEdit struct {

	// The content of this status at this revision.
	// Should be HTML, but might also be plaintext in some cases.
	// Example: \u003cp\u003eHey this is a status!\u003c/p\u003e
	Content string `json:"content,omitempty"`

	// The date when this revision was created (ISO 8601 Datetime).
	// Example: 2021-07-30T09:20:25+00:00
	CreatedAt string `json:"created_at,omitempty"`

	// Custom emoji to be used when rendering status content.
	Emojis []*Emoji `json:"emojis"`

	// Media that is attached to this status.
	MediaAttachments []*Attachment `json:"media_attachments"`

	// Status marked sensitive at this revision.
	// Example: false
	Sensitive bool `json:"sensitive,omitempty"`

	// Subject, summary, or content warning for the status at this revision.
	// Example: warning nsfw
	SpoilerText string `json:"spoiler_text,omitempty"`

	// account
	Account *Account `json:"account,omitempty"`

	// poll
	Poll *Poll `json:"poll,omitempty"`
}

// Validate validates this status edit
func (m *StatusEdit) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *StatusEdit) validateEmojis(formats strfmt.Registry) error {
	if swag.IsZero(m.Emojis) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *StatusEdit) validateMediaAttachments(formats strfmt.Registry) error {
	if swag.IsZero(m.MediaAttachments) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *StatusEdit) validateAccount(formats strfmt.Registry) error {
	if swag.IsZero(m.Account) { // not required
		return nil
	}

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

	return nil
}

func (m *StatusEdit) validatePoll(formats strfmt.Registry) error {
	if swag.IsZero(m.Poll) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

func (m *StatusEdit) contextValidateEmojis(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Emojis[i] != nil {

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

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

	}

	return nil
}

func (m *StatusEdit) contextValidateMediaAttachments(ctx context.Context, formats strfmt.Registry) error {

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

		if m.MediaAttachments[i] != nil {

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

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

	}

	return nil
}

func (m *StatusEdit) contextValidateAccount(ctx context.Context, formats strfmt.Registry) error {

	if m.Account != nil {

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

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

	return nil
}

func (m *StatusEdit) contextValidatePoll(ctx context.Context, formats strfmt.Registry) error {

	if m.Poll != nil {

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

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

	return nil
}

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

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