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

// (c) 2012-2020 by Taxnexus, Inc.
// All rights reserved worldwide.
// Proprietary product; unlicensed use is not allowed

package sessions

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

	"code.tnxs.net/vernonkeenan/lib/api/members/members_models"
	"github.com/go-openapi/errors"
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag/jsonutils"
	"github.com/go-openapi/swag/typeutils"
	"github.com/go-openapi/validate"
)

// ValidateHandoffReader is a Reader for the ValidateHandoff structure.
type ValidateHandoffReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *ValidateHandoffReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) {
	switch response.Code() {
	case 200:
		result := NewValidateHandoffOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewValidateHandoffBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewValidateHandoffUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 403:
		result := NewValidateHandoffForbidden()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 500:
		result := NewValidateHandoffInternalServerError()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[POST /sessions/handoff/validate] validateHandoff", response, response.Code())
	}
}

// NewValidateHandoffOK creates a ValidateHandoffOK with default headers values
func NewValidateHandoffOK() *ValidateHandoffOK {
	return &ValidateHandoffOK{}
}

// ValidateHandoffOK describes a response with status code 200, with default header values.
//
// Token validated successfully
type ValidateHandoffOK struct {
	Payload *ValidateHandoffOKBody
}

// IsSuccess returns true when this validate handoff o k response has a 2xx status code
func (o *ValidateHandoffOK) IsSuccess() bool {
	return true
}

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

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

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

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

// Code gets the status code for the validate handoff o k response
func (o *ValidateHandoffOK) Code() int {
	return 200
}

func (o *ValidateHandoffOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffOK %s", 200, payload)
}

func (o *ValidateHandoffOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffOK %s", 200, payload)
}

func (o *ValidateHandoffOK) GetPayload() *ValidateHandoffOKBody {
	return o.Payload
}

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

	o.Payload = new(ValidateHandoffOKBody)

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

	return nil
}

// NewValidateHandoffBadRequest creates a ValidateHandoffBadRequest with default headers values
func NewValidateHandoffBadRequest() *ValidateHandoffBadRequest {
	return &ValidateHandoffBadRequest{}
}

// ValidateHandoffBadRequest describes a response with status code 400, with default header values.
//
// Invalid request parameters
type ValidateHandoffBadRequest struct {
	Payload *members_models.Error
}

// IsSuccess returns true when this validate handoff bad request response has a 2xx status code
func (o *ValidateHandoffBadRequest) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this validate handoff bad request response has a 3xx status code
func (o *ValidateHandoffBadRequest) IsRedirect() bool {
	return false
}

// IsClientError returns true when this validate handoff bad request response has a 4xx status code
func (o *ValidateHandoffBadRequest) IsClientError() bool {
	return true
}

// IsServerError returns true when this validate handoff bad request response has a 5xx status code
func (o *ValidateHandoffBadRequest) IsServerError() bool {
	return false
}

// IsCode returns true when this validate handoff bad request response a status code equal to that given
func (o *ValidateHandoffBadRequest) IsCode(code int) bool {
	return code == 400
}

// Code gets the status code for the validate handoff bad request response
func (o *ValidateHandoffBadRequest) Code() int {
	return 400
}

func (o *ValidateHandoffBadRequest) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffBadRequest %s", 400, payload)
}

func (o *ValidateHandoffBadRequest) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffBadRequest %s", 400, payload)
}

func (o *ValidateHandoffBadRequest) GetPayload() *members_models.Error {
	return o.Payload
}

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

	o.Payload = new(members_models.Error)

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

	return nil
}

// NewValidateHandoffUnauthorized creates a ValidateHandoffUnauthorized with default headers values
func NewValidateHandoffUnauthorized() *ValidateHandoffUnauthorized {
	return &ValidateHandoffUnauthorized{}
}

// ValidateHandoffUnauthorized describes a response with status code 401, with default header values.
//
// Invalid or expired token
type ValidateHandoffUnauthorized struct {
	Payload *members_models.Error
}

// IsSuccess returns true when this validate handoff unauthorized response has a 2xx status code
func (o *ValidateHandoffUnauthorized) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this validate handoff unauthorized response has a 3xx status code
func (o *ValidateHandoffUnauthorized) IsRedirect() bool {
	return false
}

// IsClientError returns true when this validate handoff unauthorized response has a 4xx status code
func (o *ValidateHandoffUnauthorized) IsClientError() bool {
	return true
}

// IsServerError returns true when this validate handoff unauthorized response has a 5xx status code
func (o *ValidateHandoffUnauthorized) IsServerError() bool {
	return false
}

// IsCode returns true when this validate handoff unauthorized response a status code equal to that given
func (o *ValidateHandoffUnauthorized) IsCode(code int) bool {
	return code == 401
}

// Code gets the status code for the validate handoff unauthorized response
func (o *ValidateHandoffUnauthorized) Code() int {
	return 401
}

func (o *ValidateHandoffUnauthorized) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffUnauthorized %s", 401, payload)
}

func (o *ValidateHandoffUnauthorized) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffUnauthorized %s", 401, payload)
}

func (o *ValidateHandoffUnauthorized) GetPayload() *members_models.Error {
	return o.Payload
}

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

	o.Payload = new(members_models.Error)

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

	return nil
}

// NewValidateHandoffForbidden creates a ValidateHandoffForbidden with default headers values
func NewValidateHandoffForbidden() *ValidateHandoffForbidden {
	return &ValidateHandoffForbidden{}
}

// ValidateHandoffForbidden describes a response with status code 403, with default header values.
//
// Domain not authorized
type ValidateHandoffForbidden struct {
	Payload *members_models.Error
}

// IsSuccess returns true when this validate handoff forbidden response has a 2xx status code
func (o *ValidateHandoffForbidden) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this validate handoff forbidden response has a 3xx status code
func (o *ValidateHandoffForbidden) IsRedirect() bool {
	return false
}

// IsClientError returns true when this validate handoff forbidden response has a 4xx status code
func (o *ValidateHandoffForbidden) IsClientError() bool {
	return true
}

// IsServerError returns true when this validate handoff forbidden response has a 5xx status code
func (o *ValidateHandoffForbidden) IsServerError() bool {
	return false
}

// IsCode returns true when this validate handoff forbidden response a status code equal to that given
func (o *ValidateHandoffForbidden) IsCode(code int) bool {
	return code == 403
}

// Code gets the status code for the validate handoff forbidden response
func (o *ValidateHandoffForbidden) Code() int {
	return 403
}

func (o *ValidateHandoffForbidden) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffForbidden %s", 403, payload)
}

func (o *ValidateHandoffForbidden) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffForbidden %s", 403, payload)
}

func (o *ValidateHandoffForbidden) GetPayload() *members_models.Error {
	return o.Payload
}

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

	o.Payload = new(members_models.Error)

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

	return nil
}

// NewValidateHandoffInternalServerError creates a ValidateHandoffInternalServerError with default headers values
func NewValidateHandoffInternalServerError() *ValidateHandoffInternalServerError {
	return &ValidateHandoffInternalServerError{}
}

// ValidateHandoffInternalServerError describes a response with status code 500, with default header values.
//
// Server Internal Error
type ValidateHandoffInternalServerError struct {
	Payload *members_models.Error
}

// IsSuccess returns true when this validate handoff internal server error response has a 2xx status code
func (o *ValidateHandoffInternalServerError) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this validate handoff internal server error response has a 3xx status code
func (o *ValidateHandoffInternalServerError) IsRedirect() bool {
	return false
}

// IsClientError returns true when this validate handoff internal server error response has a 4xx status code
func (o *ValidateHandoffInternalServerError) IsClientError() bool {
	return false
}

// IsServerError returns true when this validate handoff internal server error response has a 5xx status code
func (o *ValidateHandoffInternalServerError) IsServerError() bool {
	return true
}

// IsCode returns true when this validate handoff internal server error response a status code equal to that given
func (o *ValidateHandoffInternalServerError) IsCode(code int) bool {
	return code == 500
}

// Code gets the status code for the validate handoff internal server error response
func (o *ValidateHandoffInternalServerError) Code() int {
	return 500
}

func (o *ValidateHandoffInternalServerError) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffInternalServerError %s", 500, payload)
}

func (o *ValidateHandoffInternalServerError) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /sessions/handoff/validate][%d] validateHandoffInternalServerError %s", 500, payload)
}

func (o *ValidateHandoffInternalServerError) GetPayload() *members_models.Error {
	return o.Payload
}

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

	o.Payload = new(members_models.Error)

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

	return nil
}

// ValidateHandoffBody validate handoff body
//
// swagger:model ValidateHandoffBody
type ValidateHandoffBody struct {

	// Client IP address
	// Example: 192.168.1.100
	ClientIP string `json:"client_ip,omitempty"`

	// Requesting domain
	// Example: salesforcedevops.net
	// Required: true
	Domain *string `json:"domain"`

	// Handoff token to validate
	// Example: hoff_1234567890abcdef
	// Required: true
	HandoffToken *string `json:"handoff_token"`

	// CSRF state parameter
	// Example: random-csrf-token-123
	// Required: true
	State *string `json:"state"`
}

// Validate validates this validate handoff body
func (o *ValidateHandoffBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (o *ValidateHandoffBody) validateDomain(formats strfmt.Registry) error {

	if err := validate.Required("handoffValidate"+"."+"domain", "body", o.Domain); err != nil {
		return err
	}

	return nil
}

func (o *ValidateHandoffBody) validateHandoffToken(formats strfmt.Registry) error {

	if err := validate.Required("handoffValidate"+"."+"handoff_token", "body", o.HandoffToken); err != nil {
		return err
	}

	return nil
}

func (o *ValidateHandoffBody) validateState(formats strfmt.Registry) error {

	if err := validate.Required("handoffValidate"+"."+"state", "body", o.State); err != nil {
		return err
	}

	return nil
}

// ContextValidate validates this validate handoff body based on context it is used
func (o *ValidateHandoffBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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

// ValidateHandoffOKBody validate handoff o k body
//
// swagger:model ValidateHandoffOKBody
type ValidateHandoffOKBody struct {

	// Session expiration time
	// Format: date-time
	ExpiresAt strfmt.DateTime `json:"expires_at,omitempty"`

	// Reference to central session
	// Example: sess_abcdef1234567890
	SessionRef string `json:"session_ref,omitempty"`

	// user
	User *members_models.User `json:"user,omitempty"`
}

// Validate validates this validate handoff o k body
func (o *ValidateHandoffOKBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (o *ValidateHandoffOKBody) validateExpiresAt(formats strfmt.Registry) error {
	if typeutils.IsZero(o.ExpiresAt) { // not required
		return nil
	}

	if err := validate.FormatOf("validateHandoffOK"+"."+"expires_at", "body", "date-time", o.ExpiresAt.String(), formats); err != nil {
		return err
	}

	return nil
}

func (o *ValidateHandoffOKBody) validateUser(formats strfmt.Registry) error {
	if typeutils.IsZero(o.User) { // not required
		return nil
	}

	if o.User != nil {
		if err := o.User.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("validateHandoffOK" + "." + "user")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("validateHandoffOK" + "." + "user")
			}

			return err
		}
	}

	return nil
}

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

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

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

func (o *ValidateHandoffOKBody) contextValidateUser(ctx context.Context, formats strfmt.Registry) error {

	if o.User != nil {

		if typeutils.IsZero(o.User) { // not required
			return nil
		}

		if err := o.User.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("validateHandoffOK" + "." + "user")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("validateHandoffOK" + "." + "user")
			}

			return err
		}
	}

	return nil
}

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

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