// 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"
	"github.com/go-openapi/validate"
)

// WidgetToken widget token
//
// swagger:model WidgetToken
type WidgetToken struct {

	// inherit list
	InheritList []*WidgetTokenInheritance `json:"inheritList,omitempty"`

	// This is the name of the parent group of devices, if there is one established
	// Example: Default Device Group
	Name string `json:"name,omitempty"`

	// type
	// Read Only: true
	Type string `json:"type,omitempty"`

	// this is the name of the child group of devices, if there is one
	// Example: Devices by Type/Network
	Value string `json:"value,omitempty"`
}

// Validate validates this widget token
func (m *WidgetToken) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *WidgetToken) validateInheritList(formats strfmt.Registry) error {
	if swag.IsZero(m.InheritList) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

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

func (m *WidgetToken) contextValidateInheritList(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *WidgetToken) contextValidateType(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "type", "body", string(m.Type)); err != nil {
		return err
	}

	return nil
}

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

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