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

// HashicorpCloudResourcemanagerItemDetail Detailed information about a resource, user, or other item causing a failure.
//
// swagger:model hashicorp.cloud.resourcemanager.ItemDetail
type HashicorpCloudResourcemanagerItemDetail struct {

	// billing
	Billing *HashicorpCloudResourcemanagerBillingDetail `json:"billing,omitempty"`

	// group
	Group *HashicorpCloudResourcemanagerGroupDetail `json:"group,omitempty"`

	// resource
	Resource *HashicorpCloudResourcemanagerResourceDetail `json:"resource,omitempty"`

	// service principal
	ServicePrincipal *HashicorpCloudResourcemanagerServicePrincipalDetail `json:"service_principal,omitempty"`

	// user
	User *HashicorpCloudResourcemanagerUserDetail `json:"user,omitempty"`
}

// Validate validates this hashicorp cloud resourcemanager item detail
func (m *HashicorpCloudResourcemanagerItemDetail) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

func (m *HashicorpCloudResourcemanagerItemDetail) validateBilling(formats strfmt.Registry) error {
	if swag.IsZero(m.Billing) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudResourcemanagerItemDetail) validateGroup(formats strfmt.Registry) error {
	if swag.IsZero(m.Group) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudResourcemanagerItemDetail) validateResource(formats strfmt.Registry) error {
	if swag.IsZero(m.Resource) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudResourcemanagerItemDetail) validateServicePrincipal(formats strfmt.Registry) error {
	if swag.IsZero(m.ServicePrincipal) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudResourcemanagerItemDetail) validateUser(formats strfmt.Registry) error {
	if swag.IsZero(m.User) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

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

func (m *HashicorpCloudResourcemanagerItemDetail) contextValidateBilling(ctx context.Context, formats strfmt.Registry) error {

	if m.Billing != nil {

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

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

	return nil
}

func (m *HashicorpCloudResourcemanagerItemDetail) contextValidateGroup(ctx context.Context, formats strfmt.Registry) error {

	if m.Group != nil {

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

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

	return nil
}

func (m *HashicorpCloudResourcemanagerItemDetail) contextValidateResource(ctx context.Context, formats strfmt.Registry) error {

	if m.Resource != nil {

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

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

	return nil
}

func (m *HashicorpCloudResourcemanagerItemDetail) contextValidateServicePrincipal(ctx context.Context, formats strfmt.Registry) error {

	if m.ServicePrincipal != nil {

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

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

	return nil
}

func (m *HashicorpCloudResourcemanagerItemDetail) contextValidateUser(ctx context.Context, formats strfmt.Registry) error {

	if m.User != nil {

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

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

	return nil
}

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

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