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

// HashicorpCloudWebhookTestWebhookRequestBody hashicorp cloud webhook test webhook request body
//
// swagger:model hashicorp.cloud.webhook.TestWebhookRequestBody
type HashicorpCloudWebhookTestWebhookRequestBody struct {

	// The required information necessary for delivering the test payload.
	Config *HashicorpCloudWebhookWebhookConfig `json:"config,omitempty"`

	// The optional testing payload to send to the webhook. If not set, the webhook service delivers a generic payload.
	TestPayload *HashicorpCloudWebhookWebhookPayload `json:"test_payload,omitempty"`

	// The optional webhook UUID. If specified, the test is stored as a delivery for this webhook.
	WebhookResourceID string `json:"webhook_resource_id,omitempty"`
}

// Validate validates this hashicorp cloud webhook test webhook request body
func (m *HashicorpCloudWebhookTestWebhookRequestBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudWebhookTestWebhookRequestBody) validateConfig(formats strfmt.Registry) error {
	if swag.IsZero(m.Config) { // not required
		return nil
	}

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

	return nil
}

func (m *HashicorpCloudWebhookTestWebhookRequestBody) validateTestPayload(formats strfmt.Registry) error {
	if swag.IsZero(m.TestPayload) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this hashicorp cloud webhook test webhook request body based on the context it is used
func (m *HashicorpCloudWebhookTestWebhookRequestBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudWebhookTestWebhookRequestBody) contextValidateConfig(ctx context.Context, formats strfmt.Registry) error {

	if m.Config != nil {

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

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

	return nil
}

func (m *HashicorpCloudWebhookTestWebhookRequestBody) contextValidateTestPayload(ctx context.Context, formats strfmt.Registry) error {

	if m.TestPayload != nil {

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

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

	return nil
}

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

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