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

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// HashicorpCloudWaypointActionConfigFlavorCustom Custom mode allows users to define the HTTP method, the request body, etc.
//
// swagger:model hashicorp.cloud.waypoint.ActionConfig.Flavor.Custom
type HashicorpCloudWaypointActionConfigFlavorCustom struct {

	// A body to be submitted with the request, if required. Will be converted
	// to bytes and sent as the request body.
	Body string `json:"body,omitempty"`

	// Key value headers to send with the request
	Headers []*HashicorpCloudWaypointActionConfigFlavorCustomHeader `json:"headers"`

	// What HTTP method should be used? GET,POST,PUT,DELETE
	Method *HashicorpCloudWaypointActionConfigFlavorCustomMethod `json:"method,omitempty"`

	// The full URL this request should make when invoked
	URL string `json:"url,omitempty"`
}

// Validate validates this hashicorp cloud waypoint action config flavor custom
func (m *HashicorpCloudWaypointActionConfigFlavorCustom) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudWaypointActionConfigFlavorCustom) validateHeaders(formats strfmt.Registry) error {
	if swag.IsZero(m.Headers) { // not required
		return nil
	}

	for i := 0; i < len(m.Headers); i++ {
		if swag.IsZero(m.Headers[i]) { // not required
			continue
		}

		if m.Headers[i] != nil {
			if err := m.Headers[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("headers" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("headers" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *HashicorpCloudWaypointActionConfigFlavorCustom) validateMethod(formats strfmt.Registry) error {
	if swag.IsZero(m.Method) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this hashicorp cloud waypoint action config flavor custom based on the context it is used
func (m *HashicorpCloudWaypointActionConfigFlavorCustom) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *HashicorpCloudWaypointActionConfigFlavorCustom) contextValidateHeaders(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Headers); i++ {

		if m.Headers[i] != nil {

			if swag.IsZero(m.Headers[i]) { // not required
				return nil
			}

			if err := m.Headers[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("headers" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("headers" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *HashicorpCloudWaypointActionConfigFlavorCustom) contextValidateMethod(ctx context.Context, formats strfmt.Registry) error {

	if m.Method != nil {

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

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

	return nil
}

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

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