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

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

	// 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"`
}

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

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

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	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.contextValidatePrincipalType(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	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
}
