// 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 (
	"encoding/json"
	stderrors "errors"
	"fmt"
	"io"

	"code.tnxs.net/vernonkeenan/lib/api/members/members_models"
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
)

// RefreshSessionReader is a Reader for the RefreshSession structure.
type RefreshSessionReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *RefreshSessionReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (any, error) {
	switch response.Code() {
	case 200:
		result := NewRefreshSessionOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 401:
		result := NewRefreshSessionUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[POST /sessions/refresh] refreshSession", response, response.Code())
	}
}

// NewRefreshSessionOK creates a RefreshSessionOK with default headers values
func NewRefreshSessionOK() *RefreshSessionOK {
	return &RefreshSessionOK{}
}

// RefreshSessionOK describes a response with status code 200, with default header values.
//
// Token refreshed
type RefreshSessionOK struct {

	// New kvSession cookie with updated expiry
	SetCookie string

	Payload *members_models.User
}

// IsSuccess returns true when this refresh session o k response has a 2xx status code
func (o *RefreshSessionOK) IsSuccess() bool {
	return true
}

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

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

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

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

// Code gets the status code for the refresh session o k response
func (o *RefreshSessionOK) Code() int {
	return 200
}

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

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

func (o *RefreshSessionOK) GetPayload() *members_models.User {
	return o.Payload
}

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

	// hydrates response header Set-Cookie
	hdrSetCookie := response.GetHeader("Set-Cookie")

	if hdrSetCookie != "" {
		o.SetCookie = hdrSetCookie
	}

	o.Payload = new(members_models.User)

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

	return nil
}

// NewRefreshSessionUnauthorized creates a RefreshSessionUnauthorized with default headers values
func NewRefreshSessionUnauthorized() *RefreshSessionUnauthorized {
	return &RefreshSessionUnauthorized{}
}

// RefreshSessionUnauthorized describes a response with status code 401, with default header values.
//
// Access Unauthorized, invalid API-KEY was used
type RefreshSessionUnauthorized struct {
	Payload *members_models.Error
}

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

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

// IsClientError returns true when this refresh session unauthorized response has a 4xx status code
func (o *RefreshSessionUnauthorized) IsClientError() bool {
	return true
}

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

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

// Code gets the status code for the refresh session unauthorized response
func (o *RefreshSessionUnauthorized) Code() int {
	return 401
}

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

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

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

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