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

// Description description
//
// swagger:model Description
type Description struct {

	// assignments
	Assignments *Assignments `json:"assignments,omitempty"`

	// permissions
	Permissions []string `json:"permissions"`
}

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

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

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

func (m *Description) validateAssignments(formats strfmt.Registry) error {
	if swag.IsZero(m.Assignments) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *Description) contextValidateAssignments(ctx context.Context, formats strfmt.Registry) error {

	if m.Assignments != nil {

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

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

	return nil
}

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

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