package data_set_management

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

	"github.com/go-openapi/errors"
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"

	"github.com/lexis-project/lexis-backend-services-api.git/models"
)

type PostDatasetStagingDownloadReader struct {
	formats strfmt.Registry
	writer  io.Writer
}

func (o *PostDatasetStagingDownloadReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewPostDatasetStagingDownloadOK(o.writer)
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewPostDatasetStagingDownloadBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewPostDatasetStagingDownloadUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 403:
		result := NewPostDatasetStagingDownloadForbidden()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 502:
		result := NewPostDatasetStagingDownloadBadGateway()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 503:
		result := NewPostDatasetStagingDownloadServiceUnavailable()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result

	default:
		return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code())
	}
}

func NewPostDatasetStagingDownloadOK(writer io.Writer) *PostDatasetStagingDownloadOK {
	return &PostDatasetStagingDownloadOK{
		Payload: writer,
	}
}

type PostDatasetStagingDownloadOK struct {
	Payload io.Writer
}

func (o *PostDatasetStagingDownloadOK) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadOK  %+v", 200, o.Payload)
}

func (o *PostDatasetStagingDownloadOK) GetPayload() io.Writer {
	return o.Payload
}

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

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

	return nil
}

func NewPostDatasetStagingDownloadBadRequest() *PostDatasetStagingDownloadBadRequest {
	return &PostDatasetStagingDownloadBadRequest{}
}

type PostDatasetStagingDownloadBadRequest struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadBadRequest) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadBadRequest  %+v", 400, o.Payload)
}

func (o *PostDatasetStagingDownloadBadRequest) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

func NewPostDatasetStagingDownloadUnauthorized() *PostDatasetStagingDownloadUnauthorized {
	return &PostDatasetStagingDownloadUnauthorized{}
}

type PostDatasetStagingDownloadUnauthorized struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadUnauthorized) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadUnauthorized  %+v", 401, o.Payload)
}

func (o *PostDatasetStagingDownloadUnauthorized) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

func NewPostDatasetStagingDownloadForbidden() *PostDatasetStagingDownloadForbidden {
	return &PostDatasetStagingDownloadForbidden{}
}

type PostDatasetStagingDownloadForbidden struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadForbidden) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadForbidden  %+v", 403, o.Payload)
}

func (o *PostDatasetStagingDownloadForbidden) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

func NewPostDatasetStagingDownloadBadGateway() *PostDatasetStagingDownloadBadGateway {
	return &PostDatasetStagingDownloadBadGateway{}
}

type PostDatasetStagingDownloadBadGateway struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadBadGateway) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadBadGateway  %+v", 502, o.Payload)
}

func (o *PostDatasetStagingDownloadBadGateway) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

func NewPostDatasetStagingDownloadServiceUnavailable() *PostDatasetStagingDownloadServiceUnavailable {
	return &PostDatasetStagingDownloadServiceUnavailable{}
}

type PostDatasetStagingDownloadServiceUnavailable struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadServiceUnavailable) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadServiceUnavailable  %+v", 503, o.Payload)
}

func (o *PostDatasetStagingDownloadServiceUnavailable) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

type PostDatasetStagingDownloadBody struct {

	SourcePath *string `json:"source_path"`

	SourceSystem *string `json:"source_system"`
}

func (o *PostDatasetStagingDownloadBody) Validate(formats strfmt.Registry) error {
	var res []error

	if err := o.validateSourcePath(formats); err != nil {
		res = append(res, err)
	}

	if err := o.validateSourceSystem(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (o *PostDatasetStagingDownloadBody) validateSourcePath(formats strfmt.Registry) error {

	if err := validate.Required("parameters"+"."+"source_path", "body", o.SourcePath); err != nil {
		return err
	}

	return nil
}

var postDatasetStagingDownloadBodyTypeSourceSystemPropEnum []interface{}

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["lrz_staging_area"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		postDatasetStagingDownloadBodyTypeSourceSystemPropEnum = append(postDatasetStagingDownloadBodyTypeSourceSystemPropEnum, v)
	}
}

const (

	PostDatasetStagingDownloadBodySourceSystemLrzStagingArea string = "lrz_staging_area"
)

func (o *PostDatasetStagingDownloadBody) validateSourceSystemEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, postDatasetStagingDownloadBodyTypeSourceSystemPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (o *PostDatasetStagingDownloadBody) validateSourceSystem(formats strfmt.Registry) error {

	if err := validate.Required("parameters"+"."+"source_system", "body", o.SourceSystem); err != nil {
		return err
	}

	if err := o.validateSourceSystemEnum("parameters"+"."+"source_system", "body", *o.SourceSystem); err != nil {
		return err
	}

	return nil
}

func (o *PostDatasetStagingDownloadBody) MarshalBinary() ([]byte, error) {
	if o == nil {
		return nil, nil
	}
	return swag.WriteJSON(o)
}

func (o *PostDatasetStagingDownloadBody) UnmarshalBinary(b []byte) error {
	var res PostDatasetStagingDownloadBody
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*o = res
	return nil
}
// Code generated by go-swagger; DO NOT EDIT.

package data_set_management

// 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/errors"
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"

	"github.com/lexis-project/lexis-backend-services-api.git/models"
)

// PostDatasetStagingDownloadReader is a Reader for the PostDatasetStagingDownload structure.
type PostDatasetStagingDownloadReader struct {
	formats strfmt.Registry
	writer  io.Writer
}

// ReadResponse reads a server response into the received o.
func (o *PostDatasetStagingDownloadReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewPostDatasetStagingDownloadOK(o.writer)
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewPostDatasetStagingDownloadBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewPostDatasetStagingDownloadUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 403:
		result := NewPostDatasetStagingDownloadForbidden()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 502:
		result := NewPostDatasetStagingDownloadBadGateway()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 503:
		result := NewPostDatasetStagingDownloadServiceUnavailable()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result

	default:
		return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code())
	}
}

// NewPostDatasetStagingDownloadOK creates a PostDatasetStagingDownloadOK with default headers values
func NewPostDatasetStagingDownloadOK(writer io.Writer) *PostDatasetStagingDownloadOK {
	return &PostDatasetStagingDownloadOK{
		Payload: writer,
	}
}

/*PostDatasetStagingDownloadOK handles this case with default header values.

Successful request
*/
type PostDatasetStagingDownloadOK struct {
	Payload io.Writer
}

func (o *PostDatasetStagingDownloadOK) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadOK  %+v", 200, o.Payload)
}

func (o *PostDatasetStagingDownloadOK) GetPayload() io.Writer {
	return o.Payload
}

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

// NewPostDatasetStagingDownloadBadRequest creates a PostDatasetStagingDownloadBadRequest with default headers values
func NewPostDatasetStagingDownloadBadRequest() *PostDatasetStagingDownloadBadRequest {
	return &PostDatasetStagingDownloadBadRequest{}
}

/*PostDatasetStagingDownloadBadRequest handles this case with default header values.

Malformed Request
*/
type PostDatasetStagingDownloadBadRequest struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadBadRequest) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadBadRequest  %+v", 400, o.Payload)
}

func (o *PostDatasetStagingDownloadBadRequest) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

// NewPostDatasetStagingDownloadUnauthorized creates a PostDatasetStagingDownloadUnauthorized with default headers values
func NewPostDatasetStagingDownloadUnauthorized() *PostDatasetStagingDownloadUnauthorized {
	return &PostDatasetStagingDownloadUnauthorized{}
}

/*PostDatasetStagingDownloadUnauthorized handles this case with default header values.

Unauthorized
*/
type PostDatasetStagingDownloadUnauthorized struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadUnauthorized) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadUnauthorized  %+v", 401, o.Payload)
}

func (o *PostDatasetStagingDownloadUnauthorized) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

// NewPostDatasetStagingDownloadForbidden creates a PostDatasetStagingDownloadForbidden with default headers values
func NewPostDatasetStagingDownloadForbidden() *PostDatasetStagingDownloadForbidden {
	return &PostDatasetStagingDownloadForbidden{}
}

/*PostDatasetStagingDownloadForbidden handles this case with default header values.

Forbidden
*/
type PostDatasetStagingDownloadForbidden struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadForbidden) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadForbidden  %+v", 403, o.Payload)
}

func (o *PostDatasetStagingDownloadForbidden) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

// NewPostDatasetStagingDownloadBadGateway creates a PostDatasetStagingDownloadBadGateway with default headers values
func NewPostDatasetStagingDownloadBadGateway() *PostDatasetStagingDownloadBadGateway {
	return &PostDatasetStagingDownloadBadGateway{}
}

/*PostDatasetStagingDownloadBadGateway handles this case with default header values.

Bad Gateway
*/
type PostDatasetStagingDownloadBadGateway struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadBadGateway) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadBadGateway  %+v", 502, o.Payload)
}

func (o *PostDatasetStagingDownloadBadGateway) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

// NewPostDatasetStagingDownloadServiceUnavailable creates a PostDatasetStagingDownloadServiceUnavailable with default headers values
func NewPostDatasetStagingDownloadServiceUnavailable() *PostDatasetStagingDownloadServiceUnavailable {
	return &PostDatasetStagingDownloadServiceUnavailable{}
}

/*PostDatasetStagingDownloadServiceUnavailable handles this case with default header values.

Server error
*/
type PostDatasetStagingDownloadServiceUnavailable struct {
	Payload *models.ErrorResponse
}

func (o *PostDatasetStagingDownloadServiceUnavailable) Error() string {
	return fmt.Sprintf("[POST /dataset/staging/download][%d] postDatasetStagingDownloadServiceUnavailable  %+v", 503, o.Payload)
}

func (o *PostDatasetStagingDownloadServiceUnavailable) GetPayload() *models.ErrorResponse {
	return o.Payload
}

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

	o.Payload = new(models.ErrorResponse)

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

	return nil
}

/*PostDatasetStagingDownloadBody post dataset staging download body
swagger:model PostDatasetStagingDownloadBody
*/
type PostDatasetStagingDownloadBody struct {

	// source path
	// Required: true
	SourcePath *string `json:"source_path"`

	// source system
	// Required: true
	// Enum: [lrz_staging_area]
	SourceSystem *string `json:"source_system"`
}

// Validate validates this post dataset staging download body
func (o *PostDatasetStagingDownloadBody) Validate(formats strfmt.Registry) error {
	var res []error

	if err := o.validateSourcePath(formats); err != nil {
		res = append(res, err)
	}

	if err := o.validateSourceSystem(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (o *PostDatasetStagingDownloadBody) validateSourcePath(formats strfmt.Registry) error {

	if err := validate.Required("parameters"+"."+"source_path", "body", o.SourcePath); err != nil {
		return err
	}

	return nil
}

var postDatasetStagingDownloadBodyTypeSourceSystemPropEnum []interface{}

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["lrz_staging_area"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		postDatasetStagingDownloadBodyTypeSourceSystemPropEnum = append(postDatasetStagingDownloadBodyTypeSourceSystemPropEnum, v)
	}
}

const (

	// PostDatasetStagingDownloadBodySourceSystemLrzStagingArea captures enum value "lrz_staging_area"
	PostDatasetStagingDownloadBodySourceSystemLrzStagingArea string = "lrz_staging_area"
)

// prop value enum
func (o *PostDatasetStagingDownloadBody) validateSourceSystemEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, postDatasetStagingDownloadBodyTypeSourceSystemPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (o *PostDatasetStagingDownloadBody) validateSourceSystem(formats strfmt.Registry) error {

	if err := validate.Required("parameters"+"."+"source_system", "body", o.SourceSystem); err != nil {
		return err
	}

	// value enum
	if err := o.validateSourceSystemEnum("parameters"+"."+"source_system", "body", *o.SourceSystem); err != nil {
		return err
	}

	return nil
}

// MarshalBinary interface implementation
func (o *PostDatasetStagingDownloadBody) MarshalBinary() ([]byte, error) {
	if o == nil {
		return nil, nil
	}
	return swag.WriteJSON(o)
}

// UnmarshalBinary interface implementation
func (o *PostDatasetStagingDownloadBody) UnmarshalBinary(b []byte) error {
	var res PostDatasetStagingDownloadBody
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*o = res
	return nil
}
