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

// DefaultPolicies Default interaction policies to use for new statuses by requesting account.
//
// swagger:model DefaultPolicies
type DefaultPolicies struct {

	// direct
	Direct *InteractionPolicy `json:"direct,omitempty"`

	// private
	Private *InteractionPolicy `json:"private,omitempty"`

	// public
	Public *InteractionPolicy `json:"public,omitempty"`

	// unlisted
	Unlisted *InteractionPolicy `json:"unlisted,omitempty"`
}

// Validate validates this default policies
func (m *DefaultPolicies) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *DefaultPolicies) validateDirect(formats strfmt.Registry) error {
	if swag.IsZero(m.Direct) { // not required
		return nil
	}

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

	return nil
}

func (m *DefaultPolicies) validatePrivate(formats strfmt.Registry) error {
	if swag.IsZero(m.Private) { // not required
		return nil
	}

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

	return nil
}

func (m *DefaultPolicies) validatePublic(formats strfmt.Registry) error {
	if swag.IsZero(m.Public) { // not required
		return nil
	}

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

	return nil
}

func (m *DefaultPolicies) validateUnlisted(formats strfmt.Registry) error {
	if swag.IsZero(m.Unlisted) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

func (m *DefaultPolicies) contextValidateDirect(ctx context.Context, formats strfmt.Registry) error {

	if m.Direct != nil {

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

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

	return nil
}

func (m *DefaultPolicies) contextValidatePrivate(ctx context.Context, formats strfmt.Registry) error {

	if m.Private != nil {

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

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

	return nil
}

func (m *DefaultPolicies) contextValidatePublic(ctx context.Context, formats strfmt.Registry) error {

	if m.Public != nil {

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

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

	return nil
}

func (m *DefaultPolicies) contextValidateUnlisted(ctx context.Context, formats strfmt.Registry) error {

	if m.Unlisted != nil {

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

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

	return nil
}

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

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