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

package script

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

import (
	"fmt"

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

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

/*
Client for script 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 {
	Add(params *AddParams, opts ...ClientOption) (*AddNoContent, error)

	Browse(params *BrowseParams, opts ...ClientOption) (*BrowseOK, error)

	Delete1(params *Delete1Params, opts ...ClientOption) (*Delete1NoContent, error)

	Edit(params *EditParams, opts ...ClientOption) (*EditNoContent, error)

	Read1(params *Read1Params, opts ...ClientOption) (*Read1OK, error)

	Run1(params *Run1Params, opts ...ClientOption) (*Run1OK, error)

	SetTransport(transport runtime.ClientTransport)
}

/*
Add adds a new script
*/
func (a *Client) Add(params *AddParams, opts ...ClientOption) (*AddNoContent, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewAddParams()
	}
	op := &runtime.ClientOperation{
		ID:                 "add",
		Method:             "POST",
		PathPattern:        "/v1/script",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &AddReader{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.(*AddNoContent)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for add: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
Browse lists all stored scripts
*/
func (a *Client) Browse(params *BrowseParams, opts ...ClientOption) (*BrowseOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewBrowseParams()
	}
	op := &runtime.ClientOperation{
		ID:                 "browse",
		Method:             "GET",
		PathPattern:        "/v1/script",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &BrowseReader{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.(*BrowseOK)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for browse: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
Delete1 deletes stored script by name
*/
func (a *Client) Delete1(params *Delete1Params, opts ...ClientOption) (*Delete1NoContent, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewDelete1Params()
	}
	op := &runtime.ClientOperation{
		ID:                 "delete_1",
		Method:             "DELETE",
		PathPattern:        "/v1/script/{name}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &Delete1Reader{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.(*Delete1NoContent)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for delete_1: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
Edit updates stored script by name
*/
func (a *Client) Edit(params *EditParams, opts ...ClientOption) (*EditNoContent, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewEditParams()
	}
	op := &runtime.ClientOperation{
		ID:                 "edit",
		Method:             "PUT",
		PathPattern:        "/v1/script/{name}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &EditReader{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.(*EditNoContent)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for edit: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
Read1 reads stored script by name
*/
func (a *Client) Read1(params *Read1Params, opts ...ClientOption) (*Read1OK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewRead1Params()
	}
	op := &runtime.ClientOperation{
		ID:                 "read_1",
		Method:             "GET",
		PathPattern:        "/v1/script/{name}",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &Read1Reader{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.(*Read1OK)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for read_1: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

/*
Run1 runs stored script by name
*/
func (a *Client) Run1(params *Run1Params, opts ...ClientOption) (*Run1OK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewRun1Params()
	}
	op := &runtime.ClientOperation{
		ID:                 "run_1",
		Method:             "POST",
		PathPattern:        "/v1/script/{name}/run",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json", "text/plain"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &Run1Reader{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.(*Run1OK)
	if ok {
		return success, nil
	}
	// unexpected success response
	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for run_1: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

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