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

package admin

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

// AdminCreatePublicKeyReader is a Reader for the AdminCreatePublicKey structure.
type AdminCreatePublicKeyReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *AdminCreatePublicKeyReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 201:
		result := NewAdminCreatePublicKeyCreated()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 403:
		result := NewAdminCreatePublicKeyForbidden()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 422:
		result := NewAdminCreatePublicKeyUnprocessableEntity()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[POST /admin/users/{username}/keys] adminCreatePublicKey", response, response.Code())
	}
}

// NewAdminCreatePublicKeyCreated creates a AdminCreatePublicKeyCreated with default headers values
func NewAdminCreatePublicKeyCreated() *AdminCreatePublicKeyCreated {
	return &AdminCreatePublicKeyCreated{}
}

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

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

// IsSuccess returns true when this admin create public key created response has a 2xx status code
func (o *AdminCreatePublicKeyCreated) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this admin create public key created response has a 3xx status code
func (o *AdminCreatePublicKeyCreated) IsRedirect() bool {
	return false
}

// IsClientError returns true when this admin create public key created response has a 4xx status code
func (o *AdminCreatePublicKeyCreated) IsClientError() bool {
	return false
}

// IsServerError returns true when this admin create public key created response has a 5xx status code
func (o *AdminCreatePublicKeyCreated) IsServerError() bool {
	return false
}

// IsCode returns true when this admin create public key created response a status code equal to that given
func (o *AdminCreatePublicKeyCreated) IsCode(code int) bool {
	return code == 201
}

// Code gets the status code for the admin create public key created response
func (o *AdminCreatePublicKeyCreated) Code() int {
	return 201
}

func (o *AdminCreatePublicKeyCreated) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /admin/users/{username}/keys][%d] adminCreatePublicKeyCreated %s", 201, payload)
}

func (o *AdminCreatePublicKeyCreated) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /admin/users/{username}/keys][%d] adminCreatePublicKeyCreated %s", 201, payload)
}

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

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

// NewAdminCreatePublicKeyForbidden creates a AdminCreatePublicKeyForbidden with default headers values
func NewAdminCreatePublicKeyForbidden() *AdminCreatePublicKeyForbidden {
	return &AdminCreatePublicKeyForbidden{}
}

/*
AdminCreatePublicKeyForbidden describes a response with status code 403, with default header values.

APIForbiddenError is a forbidden error response
*/
type AdminCreatePublicKeyForbidden struct {
	Message string
	URL     string
}

// IsSuccess returns true when this admin create public key forbidden response has a 2xx status code
func (o *AdminCreatePublicKeyForbidden) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this admin create public key forbidden response has a 3xx status code
func (o *AdminCreatePublicKeyForbidden) IsRedirect() bool {
	return false
}

// IsClientError returns true when this admin create public key forbidden response has a 4xx status code
func (o *AdminCreatePublicKeyForbidden) IsClientError() bool {
	return true
}

// IsServerError returns true when this admin create public key forbidden response has a 5xx status code
func (o *AdminCreatePublicKeyForbidden) IsServerError() bool {
	return false
}

// IsCode returns true when this admin create public key forbidden response a status code equal to that given
func (o *AdminCreatePublicKeyForbidden) IsCode(code int) bool {
	return code == 403
}

// Code gets the status code for the admin create public key forbidden response
func (o *AdminCreatePublicKeyForbidden) Code() int {
	return 403
}

func (o *AdminCreatePublicKeyForbidden) Error() string {
	return fmt.Sprintf("[POST /admin/users/{username}/keys][%d] adminCreatePublicKeyForbidden", 403)
}

func (o *AdminCreatePublicKeyForbidden) String() string {
	return fmt.Sprintf("[POST /admin/users/{username}/keys][%d] adminCreatePublicKeyForbidden", 403)
}

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

// NewAdminCreatePublicKeyUnprocessableEntity creates a AdminCreatePublicKeyUnprocessableEntity with default headers values
func NewAdminCreatePublicKeyUnprocessableEntity() *AdminCreatePublicKeyUnprocessableEntity {
	return &AdminCreatePublicKeyUnprocessableEntity{}
}

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

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

// IsSuccess returns true when this admin create public key unprocessable entity response has a 2xx status code
func (o *AdminCreatePublicKeyUnprocessableEntity) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this admin create public key unprocessable entity response has a 3xx status code
func (o *AdminCreatePublicKeyUnprocessableEntity) IsRedirect() bool {
	return false
}

// IsClientError returns true when this admin create public key unprocessable entity response has a 4xx status code
func (o *AdminCreatePublicKeyUnprocessableEntity) IsClientError() bool {
	return true
}

// IsServerError returns true when this admin create public key unprocessable entity response has a 5xx status code
func (o *AdminCreatePublicKeyUnprocessableEntity) IsServerError() bool {
	return false
}

// IsCode returns true when this admin create public key unprocessable entity response a status code equal to that given
func (o *AdminCreatePublicKeyUnprocessableEntity) IsCode(code int) bool {
	return code == 422
}

// Code gets the status code for the admin create public key unprocessable entity response
func (o *AdminCreatePublicKeyUnprocessableEntity) Code() int {
	return 422
}

func (o *AdminCreatePublicKeyUnprocessableEntity) Error() string {
	return fmt.Sprintf("[POST /admin/users/{username}/keys][%d] adminCreatePublicKeyUnprocessableEntity", 422)
}

func (o *AdminCreatePublicKeyUnprocessableEntity) String() string {
	return fmt.Sprintf("[POST /admin/users/{username}/keys][%d] adminCreatePublicKeyUnprocessableEntity", 422)
}

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