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

// HashicorpCloudWaypointV20241122ActionConfigFlavorCustom Custom mode allows users to define the HTTP method, the request body, etc.
//
// swagger:model hashicorp.cloud.waypoint.v20241122.ActionConfig.Flavor.Custom
type HashicorpCloudWaypointV20241122ActionConfigFlavorCustom 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 []*HashicorpCloudWaypointV20241122ActionConfigFlavorCustomHeader `json:"headers"`

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

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

// Validate validates this hashicorp cloud waypoint v20241122 action config flavor custom
func (m *HashicorpCloudWaypointV20241122ActionConfigFlavorCustom) 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 *HashicorpCloudWaypointV20241122ActionConfigFlavorCustom) 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 *HashicorpCloudWaypointV20241122ActionConfigFlavorCustom) 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 v20241122 action config flavor custom based on the context it is used
func (m *HashicorpCloudWaypointV20241122ActionConfigFlavorCustom) 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 *HashicorpCloudWaypointV20241122ActionConfigFlavorCustom) 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 *HashicorpCloudWaypointV20241122ActionConfigFlavorCustom) 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 *HashicorpCloudWaypointV20241122ActionConfigFlavorCustom) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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