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

// UserAddEmailReader is a Reader for the UserAddEmail structure.
type UserAddEmailReader struct {
	formats strfmt.Registry
}

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

// NewUserAddEmailCreated creates a UserAddEmailCreated with default headers values
func NewUserAddEmailCreated() *UserAddEmailCreated {
	return &UserAddEmailCreated{}
}

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

EmailList
*/
type UserAddEmailCreated struct {
	Payload []*models.Email
}

// IsSuccess returns true when this user add email created response has a 2xx status code
func (o *UserAddEmailCreated) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this user add email created response has a 3xx status code
func (o *UserAddEmailCreated) IsRedirect() bool {
	return false
}

// IsClientError returns true when this user add email created response has a 4xx status code
func (o *UserAddEmailCreated) IsClientError() bool {
	return false
}

// IsServerError returns true when this user add email created response has a 5xx status code
func (o *UserAddEmailCreated) IsServerError() bool {
	return false
}

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

// Code gets the status code for the user add email created response
func (o *UserAddEmailCreated) Code() int {
	return 201
}

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

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

func (o *UserAddEmailCreated) GetPayload() []*models.Email {
	return o.Payload
}

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

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

	return nil
}

// NewUserAddEmailUnprocessableEntity creates a UserAddEmailUnprocessableEntity with default headers values
func NewUserAddEmailUnprocessableEntity() *UserAddEmailUnprocessableEntity {
	return &UserAddEmailUnprocessableEntity{}
}

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

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

// IsSuccess returns true when this user add email unprocessable entity response has a 2xx status code
func (o *UserAddEmailUnprocessableEntity) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this user add email unprocessable entity response has a 3xx status code
func (o *UserAddEmailUnprocessableEntity) IsRedirect() bool {
	return false
}

// IsClientError returns true when this user add email unprocessable entity response has a 4xx status code
func (o *UserAddEmailUnprocessableEntity) IsClientError() bool {
	return true
}

// IsServerError returns true when this user add email unprocessable entity response has a 5xx status code
func (o *UserAddEmailUnprocessableEntity) IsServerError() bool {
	return false
}

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

// Code gets the status code for the user add email unprocessable entity response
func (o *UserAddEmailUnprocessableEntity) Code() int {
	return 422
}

func (o *UserAddEmailUnprocessableEntity) Error() string {
	return fmt.Sprintf("[POST /user/emails][%d] userAddEmailUnprocessableEntity", 422)
}

func (o *UserAddEmailUnprocessableEntity) String() string {
	return fmt.Sprintf("[POST /user/emails][%d] userAddEmailUnprocessableEntity", 422)
}

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