// 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 sessions

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 sessions API client.
func New(transport runtime.ContextualTransport, formats strfmt.Registry) ClientService {
	return &Client{transport: transport, formats: formats}
}

// New creates a new sessions 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 sessions 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 sessions 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 {

	// CreateHandoff create handoff token for cross domain authentication.
	CreateHandoff(params *CreateHandoffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateHandoffOK, error)

	// CreateHandoffContext create handoff token for cross domain authentication.
	CreateHandoffContext(ctx context.Context, params *CreateHandoffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateHandoffOK, error)

	// CreateSession create new session sign in.
	CreateSession(params *CreateSessionParams, opts ...ClientOption) (*CreateSessionOK, error)

	// CreateSessionContext create new session sign in.
	CreateSessionContext(ctx context.Context, params *CreateSessionParams, opts ...ClientOption) (*CreateSessionOK, error)

	// DeleteSession delete current session log out.
	DeleteSession(params *DeleteSessionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteSessionNoContent, error)

	// DeleteSessionContext delete current session log out.
	DeleteSessionContext(ctx context.Context, params *DeleteSessionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteSessionNoContent, error)

	// GetMe get current user.
	GetMe(params *GetMeParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetMeOK, error)

	// GetMeContext get current user.
	GetMeContext(ctx context.Context, params *GetMeParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetMeOK, error)

	// RefreshSession refresh session cookie.
	RefreshSession(params *RefreshSessionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RefreshSessionOK, error)

	// RefreshSessionContext refresh session cookie.
	RefreshSessionContext(ctx context.Context, params *RefreshSessionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RefreshSessionOK, error)

	// ValidateHandoff validate and consume handoff token.
	ValidateHandoff(params *ValidateHandoffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ValidateHandoffOK, error)

	// ValidateHandoffContext validate and consume handoff token.
	ValidateHandoffContext(ctx context.Context, params *ValidateHandoffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ValidateHandoffOK, error)

	SetTransport(transport runtime.ContextualTransport)
}

// CreateHandoff creates handoff token for cross domain authentication.
//
// 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.CreateHandoffContext] instead.
func (a *Client) CreateHandoff(params *CreateHandoffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateHandoffOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// CreateHandoffContext creates handoff token for cross domain authentication.
//
// Do not use the deprecated [CreateHandoffParams.Context] with this method: it would be ignored.
func (a *Client) CreateHandoffContext(ctx context.Context, params *CreateHandoffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateHandoffOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewCreateHandoffParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "createHandoff",
		Method:             "POST",
		PathPattern:        "/sessions/handoff/create",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &CreateHandoffReader{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.(*CreateHandoffOK)
	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 createHandoff: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

// CreateSession creates new session sign in.
//
// 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.CreateSessionContext] instead.
func (a *Client) CreateSession(params *CreateSessionParams, opts ...ClientOption) (*CreateSessionOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

	return a.CreateSessionContext(ctx, params, opts...)
}

// CreateSessionContext creates new session sign in.
//
// Do not use the deprecated [CreateSessionParams.Context] with this method: it would be ignored.
func (a *Client) CreateSessionContext(ctx context.Context, params *CreateSessionParams, opts ...ClientOption) (*CreateSessionOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewCreateSessionParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "createSession",
		Method:             "POST",
		PathPattern:        "/sessions",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &CreateSessionReader{formats: a.formats},
		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.(*CreateSessionOK)
	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 createSession: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

// DeleteSession deletes current session log out.
//
// 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.DeleteSessionContext] instead.
func (a *Client) DeleteSession(params *DeleteSessionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteSessionNoContent, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// DeleteSessionContext deletes current session log out.
//
// Do not use the deprecated [DeleteSessionParams.Context] with this method: it would be ignored.
func (a *Client) DeleteSessionContext(ctx context.Context, params *DeleteSessionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteSessionNoContent, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewDeleteSessionParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "deleteSession",
		Method:             "DELETE",
		PathPattern:        "/sessions/current",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &DeleteSessionReader{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.(*DeleteSessionNoContent)
	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 deleteSession: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

// GetMe gets current user.
//
// 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.GetMeContext] instead.
func (a *Client) GetMe(params *GetMeParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetMeOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// GetMeContext gets current user.
//
// Do not use the deprecated [GetMeParams.Context] with this method: it would be ignored.
func (a *Client) GetMeContext(ctx context.Context, params *GetMeParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetMeOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewGetMeParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "getMe",
		Method:             "GET",
		PathPattern:        "/sessions/me",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &GetMeReader{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.(*GetMeOK)
	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 getMe: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

// RefreshSession refreshes session cookie.
//
// 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.RefreshSessionContext] instead.
func (a *Client) RefreshSession(params *RefreshSessionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RefreshSessionOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// RefreshSessionContext refreshes session cookie.
//
// Do not use the deprecated [RefreshSessionParams.Context] with this method: it would be ignored.
func (a *Client) RefreshSessionContext(ctx context.Context, params *RefreshSessionParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*RefreshSessionOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewRefreshSessionParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "refreshSession",
		Method:             "POST",
		PathPattern:        "/sessions/refresh",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &RefreshSessionReader{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.(*RefreshSessionOK)
	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 refreshSession: API contract not enforced by server. Client expected to get an error, but got: %T", result)
	panic(msg)
}

// ValidateHandoff validates and consume handoff token.
//
// 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.ValidateHandoffContext] instead.
func (a *Client) ValidateHandoff(params *ValidateHandoffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ValidateHandoffOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// ValidateHandoffContext validates and consume handoff token.
//
// Do not use the deprecated [ValidateHandoffParams.Context] with this method: it would be ignored.
func (a *Client) ValidateHandoffContext(ctx context.Context, params *ValidateHandoffParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ValidateHandoffOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewValidateHandoffParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "validateHandoff",
		Method:             "POST",
		PathPattern:        "/sessions/handoff/validate",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &ValidateHandoffReader{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.(*ValidateHandoffOK)
	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 validateHandoff: 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 [SessionsParams].
	ctx context.Context
}
