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

// InteractionPolicy Interaction policy of a status.
//
// swagger:model InteractionPolicy
type InteractionPolicy struct {

	// can favourite
	CanFavourite *PolicyRules `json:"can_favourite,omitempty"`

	// can reblog
	CanReblog *PolicyRules `json:"can_reblog,omitempty"`

	// can reply
	CanReply *PolicyRules `json:"can_reply,omitempty"`
}

// Validate validates this interaction policy
func (m *InteractionPolicy) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *InteractionPolicy) validateCanFavourite(formats strfmt.Registry) error {
	if swag.IsZero(m.CanFavourite) { // not required
		return nil
	}

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

	return nil
}

func (m *InteractionPolicy) validateCanReblog(formats strfmt.Registry) error {
	if swag.IsZero(m.CanReblog) { // not required
		return nil
	}

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

	return nil
}

func (m *InteractionPolicy) validateCanReply(formats strfmt.Registry) error {
	if swag.IsZero(m.CanReply) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

func (m *InteractionPolicy) contextValidateCanFavourite(ctx context.Context, formats strfmt.Registry) error {

	if m.CanFavourite != nil {

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

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

	return nil
}

func (m *InteractionPolicy) contextValidateCanReblog(ctx context.Context, formats strfmt.Registry) error {

	if m.CanReblog != nil {

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

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

	return nil
}

func (m *InteractionPolicy) contextValidateCanReply(ctx context.Context, formats strfmt.Registry) error {

	if m.CanReply != nil {

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

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

	return nil
}

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

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