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

package backup

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

import (
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
)

// New creates a new backup API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
	return &Client{transport: transport, formats: formats}
}

/*
Client for backup API
*/
type Client struct {
	transport runtime.ClientTransport
	formats   strfmt.Registry
}

// ClientOption is the option for Client methods
type ClientOption func(*runtime.ClientOperation)

// ClientService is the interface for Client methods
type ClientService interface {
	CreateBackup(params *CreateBackupParams, opts ...ClientOption) (*CreateBackupOK, error)

	DeleteBackup(params *DeleteBackupParams, opts ...ClientOption) (*DeleteBackupOK, error)

	GetBackupOfCluster(params *GetBackupOfClusterParams, opts ...ClientOption) (*GetBackupOfClusterOK, error)

	ListBackUpOfCluster(params *ListBackUpOfClusterParams, opts ...ClientOption) (*ListBackUpOfClusterOK, error)

	SetTransport(transport runtime.ClientTransport)
}

/*
	CreateBackup creates a backup for a cluster

	- For TiDB Dedicated clusters, you can create as many manual backups as you need.

- For TiDB Serverless clusters, you cannot create backups via API. You can use [Dumpling](https://docs.pingcap.com/tidb/stable/dumpling-overview) to export your data as backups.
*/
func (a *Client) CreateBackup(params *CreateBackupParams, opts ...ClientOption) (*CreateBackupOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewCreateBackupParams()
	}
	op := &runtime.ClientOperation{
		ID:                 "CreateBackup",
		Method:             "POST",
		PathPattern:        "/api/v1beta/projects/{project_id}/clusters/{cluster_id}/backups",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &CreateBackupReader{formats: a.formats},
		Context:            params.Context,
		Client:             params.HTTPClient,
	}
	for _, opt := range opts {
		opt(op)
	}

	result, err := a.transport.Submit(op)
	if err != nil {
		return nil, err
	}
	success, ok := result.(*CreateBackupOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	unexpectedSuccess := result.(*CreateBackupDefault)
	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}

/*
DeleteBackup deletes a backup for a cluster

For TiDB Serverless clusters, you cannot manage backups via API. You can use [Dumpling](https://docs.pingcap.com/tidb/stable/dumpling-overview) to export your data as backups.
*/
func (a *Client) DeleteBackup(params *DeleteBackupParams, opts ...ClientOption) (*DeleteBackupOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewDeleteBackupParams()
	}
	op := &runtime.ClientOperation{
		ID:                 "DeleteBackup",
		Method:             "DELETE",
		PathPattern:        "/api/v1beta/projects/{project_id}/clusters/{cluster_id}/backups/{backup_id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &DeleteBackupReader{formats: a.formats},
		Context:            params.Context,
		Client:             params.HTTPClient,
	}
	for _, opt := range opts {
		opt(op)
	}

	result, err := a.transport.Submit(op)
	if err != nil {
		return nil, err
	}
	success, ok := result.(*DeleteBackupOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	unexpectedSuccess := result.(*DeleteBackupDefault)
	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}

/*
GetBackupOfCluster gets a backup for a cluster

For TiDB Serverless clusters, you cannot manage backups via API. You can use [Dumpling](https://docs.pingcap.com/tidb/stable/dumpling-overview) to export your data as backups.
*/
func (a *Client) GetBackupOfCluster(params *GetBackupOfClusterParams, opts ...ClientOption) (*GetBackupOfClusterOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewGetBackupOfClusterParams()
	}
	op := &runtime.ClientOperation{
		ID:                 "GetBackupOfCluster",
		Method:             "GET",
		PathPattern:        "/api/v1beta/projects/{project_id}/clusters/{cluster_id}/backups/{backup_id}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &GetBackupOfClusterReader{formats: a.formats},
		Context:            params.Context,
		Client:             params.HTTPClient,
	}
	for _, opt := range opts {
		opt(op)
	}

	result, err := a.transport.Submit(op)
	if err != nil {
		return nil, err
	}
	success, ok := result.(*GetBackupOfClusterOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	unexpectedSuccess := result.(*GetBackupOfClusterDefault)
	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}

/*
ListBackUpOfCluster lists all backups for a cluster

For TiDB Serverless clusters, you cannot manage backups via API. You can use [Dumpling](https://docs.pingcap.com/tidb/stable/dumpling-overview) to export your data as backups.
*/
func (a *Client) ListBackUpOfCluster(params *ListBackUpOfClusterParams, opts ...ClientOption) (*ListBackUpOfClusterOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewListBackUpOfClusterParams()
	}
	op := &runtime.ClientOperation{
		ID:                 "ListBackUpOfCluster",
		Method:             "GET",
		PathPattern:        "/api/v1beta/projects/{project_id}/clusters/{cluster_id}/backups",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"https"},
		Params:             params,
		Reader:             &ListBackUpOfClusterReader{formats: a.formats},
		Context:            params.Context,
		Client:             params.HTTPClient,
	}
	for _, opt := range opts {
		opt(op)
	}

	result, err := a.transport.Submit(op)
	if err != nil {
		return nil, err
	}
	success, ok := result.(*ListBackUpOfClusterOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	unexpectedSuccess := result.(*ListBackUpOfClusterDefault)
	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}

// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
	a.transport = transport
}
