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

// CreateSessionReader is a Reader for the CreateSession structure.
type CreateSessionReader struct {
	formats strfmt.Registry
}

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

// NewCreateSessionOK creates a CreateSessionOK with default headers values
func NewCreateSessionOK() *CreateSessionOK {
	return &CreateSessionOK{}
}

// CreateSessionOK describes a response with status code 200, with default header values.
//
// Successful sign-in
type CreateSessionOK struct {

	// kvSession=<jwt>; HttpOnly; Secure; SameSite=None; Domain=.keenanvision.net; Path=/; Max-Age=5400
	//
	SetCookie string

	Payload *members_models.User
}

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

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

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

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

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

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

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

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

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

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

// NewCreateSessionUnauthorized creates a CreateSessionUnauthorized with default headers values
func NewCreateSessionUnauthorized() *CreateSessionUnauthorized {
	return &CreateSessionUnauthorized{}
}

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

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

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

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

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

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

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

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

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

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

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

// NewCreateSessionTooManyRequests creates a CreateSessionTooManyRequests with default headers values
func NewCreateSessionTooManyRequests() *CreateSessionTooManyRequests {
	return &CreateSessionTooManyRequests{}
}

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

// IsSuccess returns true when this create session too many requests response has a 2xx status code
func (o *CreateSessionTooManyRequests) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this create session too many requests response has a 3xx status code
func (o *CreateSessionTooManyRequests) IsRedirect() bool {
	return false
}

// IsClientError returns true when this create session too many requests response has a 4xx status code
func (o *CreateSessionTooManyRequests) IsClientError() bool {
	return true
}

// IsServerError returns true when this create session too many requests response has a 5xx status code
func (o *CreateSessionTooManyRequests) IsServerError() bool {
	return false
}

// IsCode returns true when this create session too many requests response a status code equal to that given
func (o *CreateSessionTooManyRequests) IsCode(code int) bool {
	return code == 429
}

// Code gets the status code for the create session too many requests response
func (o *CreateSessionTooManyRequests) Code() int {
	return 429
}

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

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

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

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