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

// HashicorpCloudIamSearchPrincipalsResult SearchPrincipalsResult is the result type contained the response of the
// SearchPrincipals rpc.
//
// swagger:model hashicorp.cloud.iam.SearchPrincipalsResult
type HashicorpCloudIamSearchPrincipalsResult struct {

	// email is the email address of the principal.
	Email string `json:"email,omitempty"`

	// id is the ID of the principal.
	ID string `json:"id,omitempty"`

	// identity_types is an array of the identity types for a user.
	IdentityTypes []*HashicorpCloudIamUserPrincipalIdentityType `json:"identity_types"`

	// name is the name of the principal.
	Name string `json:"name,omitempty"`

	// principal_type is the type of principal (user, service principal, group, etc.).
	PrincipalType *HashicorpCloudIamPrincipalType `json:"principal_type,omitempty"`

	// resource_name is the resource name for the principal
	ResourceName string `json:"resource_name,omitempty"`
}

// Validate validates this hashicorp cloud iam search principals result
func (m *HashicorpCloudIamSearchPrincipalsResult) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudIamSearchPrincipalsResult) validateIdentityTypes(formats strfmt.Registry) error {
	if swag.IsZero(m.IdentityTypes) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *HashicorpCloudIamSearchPrincipalsResult) validatePrincipalType(formats strfmt.Registry) error {
	if swag.IsZero(m.PrincipalType) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this hashicorp cloud iam search principals result based on the context it is used
func (m *HashicorpCloudIamSearchPrincipalsResult) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudIamSearchPrincipalsResult) contextValidateIdentityTypes(ctx context.Context, formats strfmt.Registry) error {

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

		if m.IdentityTypes[i] != nil {

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

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

	}

	return nil
}

func (m *HashicorpCloudIamSearchPrincipalsResult) contextValidatePrincipalType(ctx context.Context, formats strfmt.Registry) error {

	if m.PrincipalType != nil {

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

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

	return nil
}

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

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