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

package branch_service

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

import (
	"context"
	"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/tidbcloud/ecosystem-service/pkg/branch/models"
)

// CreateBranchReader is a Reader for the CreateBranch structure.
type CreateBranchReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *CreateBranchReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewCreateBranchOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	default:
		result := NewCreateBranchDefault(response.Code())
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		if response.Code()/100 == 2 {
			return result, nil
		}
		return nil, result
	}
}

// NewCreateBranchOK creates a CreateBranchOK with default headers values
func NewCreateBranchOK() *CreateBranchOK {
	return &CreateBranchOK{}
}

/*
CreateBranchOK describes a response with status code 200, with default header values.

A successful response.
*/
type CreateBranchOK struct {
	Payload *models.OpenapiCreateBranchResp
}

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

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

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

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

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

func (o *CreateBranchOK) Error() string {
	return fmt.Sprintf("[POST /api/internal/projects/{project_id}/clusters/{cluster_id}/branches][%d] createBranchOK  %+v", 200, o.Payload)
}

func (o *CreateBranchOK) String() string {
	return fmt.Sprintf("[POST /api/internal/projects/{project_id}/clusters/{cluster_id}/branches][%d] createBranchOK  %+v", 200, o.Payload)
}

func (o *CreateBranchOK) GetPayload() *models.OpenapiCreateBranchResp {
	return o.Payload
}

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

	o.Payload = new(models.OpenapiCreateBranchResp)

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

	return nil
}

// NewCreateBranchDefault creates a CreateBranchDefault with default headers values
func NewCreateBranchDefault(code int) *CreateBranchDefault {
	return &CreateBranchDefault{
		_statusCode: code,
	}
}

/*
CreateBranchDefault describes a response with status code -1, with default header values.

An unexpected error response.
*/
type CreateBranchDefault struct {
	_statusCode int

	Payload *models.GooglerpcStatus
}

// Code gets the status code for the create branch default response
func (o *CreateBranchDefault) Code() int {
	return o._statusCode
}

// IsSuccess returns true when this create branch default response has a 2xx status code
func (o *CreateBranchDefault) IsSuccess() bool {
	return o._statusCode/100 == 2
}

// IsRedirect returns true when this create branch default response has a 3xx status code
func (o *CreateBranchDefault) IsRedirect() bool {
	return o._statusCode/100 == 3
}

// IsClientError returns true when this create branch default response has a 4xx status code
func (o *CreateBranchDefault) IsClientError() bool {
	return o._statusCode/100 == 4
}

// IsServerError returns true when this create branch default response has a 5xx status code
func (o *CreateBranchDefault) IsServerError() bool {
	return o._statusCode/100 == 5
}

// IsCode returns true when this create branch default response a status code equal to that given
func (o *CreateBranchDefault) IsCode(code int) bool {
	return o._statusCode == code
}

func (o *CreateBranchDefault) Error() string {
	return fmt.Sprintf("[POST /api/internal/projects/{project_id}/clusters/{cluster_id}/branches][%d] CreateBranch default  %+v", o._statusCode, o.Payload)
}

func (o *CreateBranchDefault) String() string {
	return fmt.Sprintf("[POST /api/internal/projects/{project_id}/clusters/{cluster_id}/branches][%d] CreateBranch default  %+v", o._statusCode, o.Payload)
}

func (o *CreateBranchDefault) GetPayload() *models.GooglerpcStatus {
	return o.Payload
}

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

	o.Payload = new(models.GooglerpcStatus)

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

	return nil
}

/*
CreateBranchBody create branch body
swagger:model CreateBranchBody
*/
type CreateBranchBody struct {

	// The name of creating branch.
	// Required: true
	BranchName *string `json:"branch_name"`

	// The id of the parent branch. If the parent is a cluster, provide the cluster id.
	// Required: true
	ParentBranchID *string `json:"parent_branch_id"`
}

// Validate validates this create branch body
func (o *CreateBranchBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (o *CreateBranchBody) validateBranchName(formats strfmt.Registry) error {

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

	return nil
}

func (o *CreateBranchBody) validateParentBranchID(formats strfmt.Registry) error {

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

	return nil
}

// ContextValidate validates this create branch body based on context it is used
func (o *CreateBranchBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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