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

package event_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"
	"strconv"

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

	"github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-radar/preview/2023-05-01/models"
)

// UpdateEventsReader is a Reader for the UpdateEvents structure.
type UpdateEventsReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *UpdateEventsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewUpdateEventsOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	default:
		result := NewUpdateEventsDefault(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
	}
}

// NewUpdateEventsOK creates a UpdateEventsOK with default headers values
func NewUpdateEventsOK() *UpdateEventsOK {
	return &UpdateEventsOK{}
}

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

A successful response.
*/
type UpdateEventsOK struct {
	Payload *models.VaultRadar20230501UpdateEventsResponse
}

// IsSuccess returns true when this update events o k response has a 2xx status code
func (o *UpdateEventsOK) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this update events o k response has a 3xx status code
func (o *UpdateEventsOK) IsRedirect() bool {
	return false
}

// IsClientError returns true when this update events o k response has a 4xx status code
func (o *UpdateEventsOK) IsClientError() bool {
	return false
}

// IsServerError returns true when this update events o k response has a 5xx status code
func (o *UpdateEventsOK) IsServerError() bool {
	return false
}

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

// Code gets the status code for the update events o k response
func (o *UpdateEventsOK) Code() int {
	return 200
}

func (o *UpdateEventsOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /2023-05-01/vault-radar/projects/{location.project_id}/events][%d] updateEventsOK %s", 200, payload)
}

func (o *UpdateEventsOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /2023-05-01/vault-radar/projects/{location.project_id}/events][%d] updateEventsOK %s", 200, payload)
}

func (o *UpdateEventsOK) GetPayload() *models.VaultRadar20230501UpdateEventsResponse {
	return o.Payload
}

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

	o.Payload = new(models.VaultRadar20230501UpdateEventsResponse)

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

	return nil
}

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

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

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

	Payload *models.RPCStatus
}

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

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

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

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

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

// Code gets the status code for the update events default response
func (o *UpdateEventsDefault) Code() int {
	return o._statusCode
}

func (o *UpdateEventsDefault) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /2023-05-01/vault-radar/projects/{location.project_id}/events][%d] UpdateEvents default %s", o._statusCode, payload)
}

func (o *UpdateEventsDefault) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /2023-05-01/vault-radar/projects/{location.project_id}/events][%d] UpdateEvents default %s", o._statusCode, payload)
}

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

func (o *UpdateEventsDefault) 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
}

/*
UpdateEventsBody UpdateEventsRequest is the request message for updating events.
swagger:model UpdateEventsBody
*/
type UpdateEventsBody struct {

	// events
	Events []*models.VaultRadar20230501EventUpdate `json:"events"`

	// location
	Location *UpdateEventsParamsBodyLocation `json:"location,omitempty"`
}

// Validate validates this update events body
func (o *UpdateEventsBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (o *UpdateEventsBody) validateEvents(formats strfmt.Registry) error {
	if swag.IsZero(o.Events) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (o *UpdateEventsBody) validateLocation(formats strfmt.Registry) error {
	if swag.IsZero(o.Location) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

func (o *UpdateEventsBody) contextValidateEvents(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(o.Events); i++ {

		if o.Events[i] != nil {

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

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

	}

	return nil
}

func (o *UpdateEventsBody) contextValidateLocation(ctx context.Context, formats strfmt.Registry) error {

	if o.Location != nil {

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

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

	return nil
}

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

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

/*
UpdateEventsParamsBodyLocation Location represents a target for an operation in HCP.
swagger:model UpdateEventsParamsBodyLocation
*/
type UpdateEventsParamsBodyLocation struct {

	// organization_id is the id of the organization.
	OrganizationID string `json:"organization_id,omitempty"`

	// region
	Region *models.LocationRegion `json:"region,omitempty"`
}

// Validate validates this update events params body location
func (o *UpdateEventsParamsBodyLocation) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (o *UpdateEventsParamsBodyLocation) validateRegion(formats strfmt.Registry) error {
	if swag.IsZero(o.Region) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (o *UpdateEventsParamsBodyLocation) contextValidateRegion(ctx context.Context, formats strfmt.Registry) error {

	if o.Region != nil {

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

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

	return nil
}

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

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