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

// APIHTTPIntegration api Http integration
//
// swagger:model apiHttpIntegration
type APIHTTPIntegration struct {

	// Application ID (UUID).
	ApplicationID string `json:"applicationId,omitempty"`

	// Payload encoding.
	Encoding *APIEncoding `json:"encoding,omitempty"`

	// Event endpoint URL.
	// The HTTP integration will POST all events to this enpoint. The request
	// will contain a query parameters "event" containing the type of the
	// event.
	EventEndpointURL string `json:"eventEndpointUrl,omitempty"`

	// HTTP headers to set when making requests.
	Headers map[string]string `json:"headers,omitempty"`
}

// Validate validates this api Http integration
func (m *APIHTTPIntegration) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *APIHTTPIntegration) validateEncoding(formats strfmt.Registry) error {
	if swag.IsZero(m.Encoding) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this api Http integration based on the context it is used
func (m *APIHTTPIntegration) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *APIHTTPIntegration) contextValidateEncoding(ctx context.Context, formats strfmt.Registry) error {

	if m.Encoding != nil {

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

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

	return nil
}

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

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