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

// HashicorpCloudResourcemanagerPolicyBindingMember PolicyBindingMember represents an identity associated with a policy binding.
//
// swagger:model hashicorp.cloud.resourcemanager.PolicyBindingMember
type HashicorpCloudResourcemanagerPolicyBindingMember struct {

	// MemberId is the unique identifier for the member.
	MemberID string `json:"member_id,omitempty"`

	// MemberType is the type of the member.
	MemberType *HashicorpCloudResourcemanagerPolicyBindingMemberType `json:"member_type,omitempty"`
}

// Validate validates this hashicorp cloud resourcemanager policy binding member
func (m *HashicorpCloudResourcemanagerPolicyBindingMember) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *HashicorpCloudResourcemanagerPolicyBindingMember) validateMemberType(formats strfmt.Registry) error {
	if swag.IsZero(m.MemberType) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this hashicorp cloud resourcemanager policy binding member based on the context it is used
func (m *HashicorpCloudResourcemanagerPolicyBindingMember) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *HashicorpCloudResourcemanagerPolicyBindingMember) contextValidateMemberType(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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