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

package user

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

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

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

	"src.opensuse.org/autogits/common/gitea-generated/models"
)

// UserCurrentPostKeyReader is a Reader for the UserCurrentPostKey structure.
type UserCurrentPostKeyReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *UserCurrentPostKeyReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 201:
		result := NewUserCurrentPostKeyCreated()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 422:
		result := NewUserCurrentPostKeyUnprocessableEntity()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[POST /user/keys] userCurrentPostKey", response, response.Code())
	}
}

// NewUserCurrentPostKeyCreated creates a UserCurrentPostKeyCreated with default headers values
func NewUserCurrentPostKeyCreated() *UserCurrentPostKeyCreated {
	return &UserCurrentPostKeyCreated{}
}

/*
UserCurrentPostKeyCreated describes a response with status code 201, with default header values.

PublicKey
*/
type UserCurrentPostKeyCreated struct {
	Payload *models.PublicKey
}

// IsSuccess returns true when this user current post key created response has a 2xx status code
func (o *UserCurrentPostKeyCreated) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this user current post key created response has a 3xx status code
func (o *UserCurrentPostKeyCreated) IsRedirect() bool {
	return false
}

// IsClientError returns true when this user current post key created response has a 4xx status code
func (o *UserCurrentPostKeyCreated) IsClientError() bool {
	return false
}

// IsServerError returns true when this user current post key created response has a 5xx status code
func (o *UserCurrentPostKeyCreated) IsServerError() bool {
	return false
}

// IsCode returns true when this user current post key created response a status code equal to that given
func (o *UserCurrentPostKeyCreated) IsCode(code int) bool {
	return code == 201
}

// Code gets the status code for the user current post key created response
func (o *UserCurrentPostKeyCreated) Code() int {
	return 201
}

func (o *UserCurrentPostKeyCreated) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /user/keys][%d] userCurrentPostKeyCreated %s", 201, payload)
}

func (o *UserCurrentPostKeyCreated) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /user/keys][%d] userCurrentPostKeyCreated %s", 201, payload)
}

func (o *UserCurrentPostKeyCreated) GetPayload() *models.PublicKey {
	return o.Payload
}

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

	o.Payload = new(models.PublicKey)

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

	return nil
}

// NewUserCurrentPostKeyUnprocessableEntity creates a UserCurrentPostKeyUnprocessableEntity with default headers values
func NewUserCurrentPostKeyUnprocessableEntity() *UserCurrentPostKeyUnprocessableEntity {
	return &UserCurrentPostKeyUnprocessableEntity{}
}

/*
UserCurrentPostKeyUnprocessableEntity describes a response with status code 422, with default header values.

APIValidationError is error format response related to input validation
*/
type UserCurrentPostKeyUnprocessableEntity struct {
	Message string
	URL     string
}

// IsSuccess returns true when this user current post key unprocessable entity response has a 2xx status code
func (o *UserCurrentPostKeyUnprocessableEntity) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this user current post key unprocessable entity response has a 3xx status code
func (o *UserCurrentPostKeyUnprocessableEntity) IsRedirect() bool {
	return false
}

// IsClientError returns true when this user current post key unprocessable entity response has a 4xx status code
func (o *UserCurrentPostKeyUnprocessableEntity) IsClientError() bool {
	return true
}

// IsServerError returns true when this user current post key unprocessable entity response has a 5xx status code
func (o *UserCurrentPostKeyUnprocessableEntity) IsServerError() bool {
	return false
}

// IsCode returns true when this user current post key unprocessable entity response a status code equal to that given
func (o *UserCurrentPostKeyUnprocessableEntity) IsCode(code int) bool {
	return code == 422
}

// Code gets the status code for the user current post key unprocessable entity response
func (o *UserCurrentPostKeyUnprocessableEntity) Code() int {
	return 422
}

func (o *UserCurrentPostKeyUnprocessableEntity) Error() string {
	return fmt.Sprintf("[POST /user/keys][%d] userCurrentPostKeyUnprocessableEntity", 422)
}

func (o *UserCurrentPostKeyUnprocessableEntity) String() string {
	return fmt.Sprintf("[POST /user/keys][%d] userCurrentPostKeyUnprocessableEntity", 422)
}

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

	// hydrates response header message
	hdrMessage := response.GetHeader("message")

	if hdrMessage != "" {
		o.Message = hdrMessage
	}

	// hydrates response header url
	hdrURL := response.GetHeader("url")

	if hdrURL != "" {
		o.URL = hdrURL
	}

	return nil
}
