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

// (c) 2012-2020 by Taxnexus, Inc.
// All rights reserved worldwide.
// Proprietary product; unlicensed use is not allowed

package tracks

import (
	"context"
	"fmt"
	"time"

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

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

// New creates a new tracks API client with basic auth credentials.
//
// It takes the following parameters:
// - host: http host (github.com).
// - basePath: any base path for the API client ("/v1", "/v3").
// - scheme: http scheme ("http", "https").
// - user: user for basic authentication header.
// - password: password for basic authentication header.
func NewClientWithBasicAuth(host, basePath, scheme, user, password string) ClientService {
	transport := httptransport.New(host, basePath, []string{scheme})
	transport.DefaultAuthentication = httptransport.BasicAuth(user, password)
	return &Client{transport: transport, formats: strfmt.Default}
}

// New creates a new tracks API client with a bearer token for authentication.
//
// It takes the following parameters:
// - host: http host (github.com).
// - basePath: any base path for the API client ("/v1", "/v3").
// - scheme: http scheme ("http", "https").
// - bearerToken: bearer token for Bearer authentication header.
func NewClientWithBearerToken(host, basePath, scheme, bearerToken string) ClientService {
	transport := httptransport.New(host, basePath, []string{scheme})
	transport.DefaultAuthentication = httptransport.BearerToken(bearerToken)
	return &Client{transport: transport, formats: strfmt.Default}
}

// Client for tracks API.
type Client struct {
	transport runtime.ContextualTransport
	formats   strfmt.Registry
}

// ClientOption may be used to customize the behavior of Client methods.
type ClientOption func(*runtime.ClientOperation)

// ClientService is the interface for Client methods.
type ClientService interface {

	// GetTracks get governed tracks.
	GetTracks(params *GetTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetTracksOK, error)

	// GetTracksContext get governed tracks.
	GetTracksContext(ctx context.Context, params *GetTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetTracksOK, error)

	// PostTracks create a governed track.
	PostTracks(params *PostTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostTracksOK, error)

	// PostTracksContext create a governed track.
	PostTracksContext(ctx context.Context, params *PostTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostTracksOK, error)

	// PutTracks update a governed track.
	PutTracks(params *PutTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutTracksOK, error)

	// PutTracksContext update a governed track.
	PutTracksContext(ctx context.Context, params *PutTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutTracksOK, error)

	SetTransport(transport runtime.ContextualTransport)
}

// GetTracks gets governed tracks.
//
// Reads Tracks whose creator is an active member of the configured Keenan Vision tenant. Owners and Managers may read all such Tracks; Contributors may read only Tracks they created. Requires members:track:read and an active native member session..
//
// This method does not support injected context.
// However, timeout and opentracing contexts are honored whenever enabled.
//
// If you need to pass a specific context, use [Client.GetTracksContext] instead.
func (a *Client) GetTracks(params *GetTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetTracksOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

	return a.GetTracksContext(ctx, params, authInfo, opts...)
}

// GetTracksContext gets governed tracks.
//
// Reads Tracks whose creator is an active member of the configured Keenan Vision tenant. Owners and Managers may read all such Tracks; Contributors may read only Tracks they created. Requires members:track:read and an active native member session..
//
// Do not use the deprecated [GetTracksParams.Context] with this method: it would be ignored.
func (a *Client) GetTracksContext(ctx context.Context, params *GetTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetTracksOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewGetTracksParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "getTracks",
		Method:             "GET",
		PathPattern:        "/tracks",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &GetTracksReader{formats: a.formats},
		AuthInfo:           authInfo,
		Client:             params.HTTPClient,
	}

	for _, opt := range opts {
		opt(op)
	}

	result, err := a.transport.SubmitContext(ctx, op)
	if err != nil {
		return nil, err
	}

	// only one success response has to be checked
	success, ok := result.(*GetTracksOK)
	if ok {
		return success, nil
	}

	// unexpected success response.

	// no default response is defined.
	//
	// safeguard: normally, in the absence of a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for getTracks: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

// PostTracks creates a governed track.
//
// Creates one Track for the configured Keenan Vision tenant. Requires members:track:create, an active native Owner or Manager session, and server-owned identity and audit fields..
//
// This method does not support injected context.
// However, timeout and opentracing contexts are honored whenever enabled.
//
// If you need to pass a specific context, use [Client.PostTracksContext] instead.
func (a *Client) PostTracks(params *PostTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostTracksOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

	return a.PostTracksContext(ctx, params, authInfo, opts...)
}

// PostTracksContext creates a governed track.
//
// Creates one Track for the configured Keenan Vision tenant. Requires members:track:create, an active native Owner or Manager session, and server-owned identity and audit fields..
//
// Do not use the deprecated [PostTracksParams.Context] with this method: it would be ignored.
func (a *Client) PostTracksContext(ctx context.Context, params *PostTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostTracksOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewPostTracksParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "postTracks",
		Method:             "POST",
		PathPattern:        "/tracks",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &PostTracksReader{formats: a.formats},
		AuthInfo:           authInfo,
		Client:             params.HTTPClient,
	}

	for _, opt := range opts {
		opt(op)
	}

	result, err := a.transport.SubmitContext(ctx, op)
	if err != nil {
		return nil, err
	}

	// only one success response has to be checked
	success, ok := result.(*PostTracksOK)
	if ok {
		return success, nil
	}

	// unexpected success response.

	// no default response is defined.
	//
	// safeguard: normally, in the absence of a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for postTracks: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

// PutTracks updates a governed track.
//
// CAS-updates one governed Track. Requires members:track:update, an active native Owner or Manager session, and the current LastModifiedDate. Creator identity and audit fields remain server-owned..
//
// This method does not support injected context.
// However, timeout and opentracing contexts are honored whenever enabled.
//
// If you need to pass a specific context, use [Client.PutTracksContext] instead.
func (a *Client) PutTracks(params *PutTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutTracksOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

	return a.PutTracksContext(ctx, params, authInfo, opts...)
}

// PutTracksContext updates a governed track.
//
// CAS-updates one governed Track. Requires members:track:update, an active native Owner or Manager session, and the current LastModifiedDate. Creator identity and audit fields remain server-owned..
//
// Do not use the deprecated [PutTracksParams.Context] with this method: it would be ignored.
func (a *Client) PutTracksContext(ctx context.Context, params *PutTracksParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutTracksOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewPutTracksParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "putTracks",
		Method:             "PUT",
		PathPattern:        "/tracks",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &PutTracksReader{formats: a.formats},
		AuthInfo:           authInfo,
		Client:             params.HTTPClient,
	}

	for _, opt := range opts {
		opt(op)
	}

	result, err := a.transport.SubmitContext(ctx, op)
	if err != nil {
		return nil, err
	}

	// only one success response has to be checked
	success, ok := result.(*PutTracksOK)
	if ok {
		return success, nil
	}

	// unexpected success response.

	// no default response is defined.
	//
	// safeguard: normally, in the absence of a default response, unknown success responses return an error above: so this is a codegen issue
	msg := fmt.Sprintf("unexpected success response for putTracks: 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.ContextualTransport) {
	a.transport = transport
}

// innerParams captures internal fields so they don't conflict with user-supplied parameters.
type innerParams struct {
	timeout time.Duration

	// Deprecated: use the operation call with context to pass the context instead of [TracksParams].
	ctx context.Context
}
