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

// HashicorpCloudIamGroupMember hashicorp cloud iam group member
//
// swagger:model hashicorp.cloud.iam.GroupMember
type HashicorpCloudIamGroupMember 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 etc.) of the group member.
	PrincipalType *HashicorpCloudIamGroupMemberPrincipalType `json:"principal_type,omitempty"`
}

// Validate validates this hashicorp cloud iam group member
func (m *HashicorpCloudIamGroupMember) 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 *HashicorpCloudIamGroupMember) 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 group member based on the context it is used
func (m *HashicorpCloudIamGroupMember) 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 *HashicorpCloudIamGroupMember) 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 *HashicorpCloudIamGroupMember) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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