// Code generated by go-swagger; DO NOT EDIT.

package application_service

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"
	"encoding/json"
	"fmt"
	"io"

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

	"git.huangwc.com/pig/pig-farm-controller/internal/infra/transport/lora/chirp_stack_proto/models"
)

// ApplicationServiceUpdateHTTPIntegrationReader is a Reader for the ApplicationServiceUpdateHTTPIntegration structure.
type ApplicationServiceUpdateHTTPIntegrationReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *ApplicationServiceUpdateHTTPIntegrationReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewApplicationServiceUpdateHTTPIntegrationOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	default:
		result := NewApplicationServiceUpdateHTTPIntegrationDefault(response.Code())
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		if response.Code()/100 == 2 {
			return result, nil
		}
		return nil, result
	}
}

// NewApplicationServiceUpdateHTTPIntegrationOK creates a ApplicationServiceUpdateHTTPIntegrationOK with default headers values
func NewApplicationServiceUpdateHTTPIntegrationOK() *ApplicationServiceUpdateHTTPIntegrationOK {
	return &ApplicationServiceUpdateHTTPIntegrationOK{}
}

/*
ApplicationServiceUpdateHTTPIntegrationOK describes a response with status code 200, with default header values.

A successful response.
*/
type ApplicationServiceUpdateHTTPIntegrationOK struct {
	Payload interface{}
}

// IsSuccess returns true when this application service update Http integration o k response has a 2xx status code
func (o *ApplicationServiceUpdateHTTPIntegrationOK) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this application service update Http integration o k response has a 3xx status code
func (o *ApplicationServiceUpdateHTTPIntegrationOK) IsRedirect() bool {
	return false
}

// IsClientError returns true when this application service update Http integration o k response has a 4xx status code
func (o *ApplicationServiceUpdateHTTPIntegrationOK) IsClientError() bool {
	return false
}

// IsServerError returns true when this application service update Http integration o k response has a 5xx status code
func (o *ApplicationServiceUpdateHTTPIntegrationOK) IsServerError() bool {
	return false
}

// IsCode returns true when this application service update Http integration o k response a status code equal to that given
func (o *ApplicationServiceUpdateHTTPIntegrationOK) IsCode(code int) bool {
	return code == 200
}

// Code gets the status code for the application service update Http integration o k response
func (o *ApplicationServiceUpdateHTTPIntegrationOK) Code() int {
	return 200
}

func (o *ApplicationServiceUpdateHTTPIntegrationOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/applications/{integration.applicationId}/integrations/http][%d] applicationServiceUpdateHttpIntegrationOK %s", 200, payload)
}

func (o *ApplicationServiceUpdateHTTPIntegrationOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/applications/{integration.applicationId}/integrations/http][%d] applicationServiceUpdateHttpIntegrationOK %s", 200, payload)
}

func (o *ApplicationServiceUpdateHTTPIntegrationOK) GetPayload() interface{} {
	return o.Payload
}

func (o *ApplicationServiceUpdateHTTPIntegrationOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

	// response payload
	if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
		return err
	}

	return nil
}

// NewApplicationServiceUpdateHTTPIntegrationDefault creates a ApplicationServiceUpdateHTTPIntegrationDefault with default headers values
func NewApplicationServiceUpdateHTTPIntegrationDefault(code int) *ApplicationServiceUpdateHTTPIntegrationDefault {
	return &ApplicationServiceUpdateHTTPIntegrationDefault{
		_statusCode: code,
	}
}

/*
ApplicationServiceUpdateHTTPIntegrationDefault describes a response with status code -1, with default header values.

An unexpected error response.
*/
type ApplicationServiceUpdateHTTPIntegrationDefault struct {
	_statusCode int

	Payload *models.RPCStatus
}

// IsSuccess returns true when this application service update Http integration default response has a 2xx status code
func (o *ApplicationServiceUpdateHTTPIntegrationDefault) IsSuccess() bool {
	return o._statusCode/100 == 2
}

// IsRedirect returns true when this application service update Http integration default response has a 3xx status code
func (o *ApplicationServiceUpdateHTTPIntegrationDefault) IsRedirect() bool {
	return o._statusCode/100 == 3
}

// IsClientError returns true when this application service update Http integration default response has a 4xx status code
func (o *ApplicationServiceUpdateHTTPIntegrationDefault) IsClientError() bool {
	return o._statusCode/100 == 4
}

// IsServerError returns true when this application service update Http integration default response has a 5xx status code
func (o *ApplicationServiceUpdateHTTPIntegrationDefault) IsServerError() bool {
	return o._statusCode/100 == 5
}

// IsCode returns true when this application service update Http integration default response a status code equal to that given
func (o *ApplicationServiceUpdateHTTPIntegrationDefault) IsCode(code int) bool {
	return o._statusCode == code
}

// Code gets the status code for the application service update Http integration default response
func (o *ApplicationServiceUpdateHTTPIntegrationDefault) Code() int {
	return o._statusCode
}

func (o *ApplicationServiceUpdateHTTPIntegrationDefault) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/applications/{integration.applicationId}/integrations/http][%d] ApplicationService_UpdateHttpIntegration default %s", o._statusCode, payload)
}

func (o *ApplicationServiceUpdateHTTPIntegrationDefault) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/applications/{integration.applicationId}/integrations/http][%d] ApplicationService_UpdateHttpIntegration default %s", o._statusCode, payload)
}

func (o *ApplicationServiceUpdateHTTPIntegrationDefault) GetPayload() *models.RPCStatus {
	return o.Payload
}

func (o *ApplicationServiceUpdateHTTPIntegrationDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

	o.Payload = new(models.RPCStatus)

	// response payload
	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
		return err
	}

	return nil
}

/*
ApplicationServiceUpdateHTTPIntegrationBody application service update HTTP integration body
swagger:model ApplicationServiceUpdateHTTPIntegrationBody
*/
type ApplicationServiceUpdateHTTPIntegrationBody struct {

	// integration
	Integration *ApplicationServiceUpdateHTTPIntegrationParamsBodyIntegration `json:"integration,omitempty"`
}

// Validate validates this application service update HTTP integration body
func (o *ApplicationServiceUpdateHTTPIntegrationBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (o *ApplicationServiceUpdateHTTPIntegrationBody) validateIntegration(formats strfmt.Registry) error {
	if swag.IsZero(o.Integration) { // not required
		return nil
	}

	if o.Integration != nil {
		if err := o.Integration.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "integration")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "integration")
			}
			return err
		}
	}

	return nil
}

// ContextValidate validate this application service update HTTP integration body based on the context it is used
func (o *ApplicationServiceUpdateHTTPIntegrationBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (o *ApplicationServiceUpdateHTTPIntegrationBody) contextValidateIntegration(ctx context.Context, formats strfmt.Registry) error {

	if o.Integration != nil {

		if swag.IsZero(o.Integration) { // not required
			return nil
		}

		if err := o.Integration.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "integration")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "integration")
			}
			return err
		}
	}

	return nil
}

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

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

/*
ApplicationServiceUpdateHTTPIntegrationParamsBodyIntegration Integration object to update.
swagger:model ApplicationServiceUpdateHTTPIntegrationParamsBodyIntegration
*/
type ApplicationServiceUpdateHTTPIntegrationParamsBodyIntegration struct {

	// Payload encoding.
	Encoding *models.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 application service update HTTP integration params body integration
func (o *ApplicationServiceUpdateHTTPIntegrationParamsBodyIntegration) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

	return nil
}

// ContextValidate validate this application service update HTTP integration params body integration based on the context it is used
func (o *ApplicationServiceUpdateHTTPIntegrationParamsBodyIntegration) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (o *ApplicationServiceUpdateHTTPIntegrationParamsBodyIntegration) contextValidateEncoding(ctx context.Context, formats strfmt.Registry) error {

	if o.Encoding != nil {

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

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

	return nil
}

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

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