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

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

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

	// GetEffectiveEntitlements resolve effective commercial access at a u t c instant.
	GetEffectiveEntitlements(params *GetEffectiveEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEffectiveEntitlementsOK, error)

	// GetEffectiveEntitlementsContext resolve effective commercial access at a u t c instant.
	GetEffectiveEntitlementsContext(ctx context.Context, params *GetEffectiveEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEffectiveEntitlementsOK, error)

	// GetEntitlements list tenant or user scoped explicit grants.
	GetEntitlements(params *GetEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEntitlementsOK, error)

	// GetEntitlementsContext list tenant or user scoped explicit grants.
	GetEntitlementsContext(ctx context.Context, params *GetEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEntitlementsOK, error)

	// GetSubscriptions list tenant scoped subscriptions.
	GetSubscriptions(params *GetSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetSubscriptionsOK, error)

	// GetSubscriptionsContext list tenant scoped subscriptions.
	GetSubscriptionsContext(ctx context.Context, params *GetSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetSubscriptionsOK, error)

	// PostEntitlements create explicit tenant or user grants.
	PostEntitlements(params *PostEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostEntitlementsOK, error)

	// PostEntitlementsContext create explicit tenant or user grants.
	PostEntitlementsContext(ctx context.Context, params *PostEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostEntitlementsOK, error)

	// PostSubscriptions create tenant subscriptions.
	PostSubscriptions(params *PostSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostSubscriptionsOK, error)

	// PostSubscriptionsContext create tenant subscriptions.
	PostSubscriptionsContext(ctx context.Context, params *PostSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostSubscriptionsOK, error)

	// PutEntitlements update revoke or expire explicit grants.
	PutEntitlements(params *PutEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutEntitlementsOK, error)

	// PutEntitlementsContext update revoke or expire explicit grants.
	PutEntitlementsContext(ctx context.Context, params *PutEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutEntitlementsOK, error)

	// PutSubscriptions update pause cancel or expire subscriptions.
	PutSubscriptions(params *PutSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutSubscriptionsOK, error)

	// PutSubscriptionsContext update pause cancel or expire subscriptions.
	PutSubscriptionsContext(ctx context.Context, params *PutSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutSubscriptionsOK, error)

	SetTransport(transport runtime.ContextualTransport)
}

// GetEffectiveEntitlements resolves effective commercial access at a u t c instant.
//
// 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.GetEffectiveEntitlementsContext] instead.
func (a *Client) GetEffectiveEntitlements(params *GetEffectiveEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEffectiveEntitlementsOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// GetEffectiveEntitlementsContext resolves effective commercial access at a u t c instant.
//
// Do not use the deprecated [GetEffectiveEntitlementsParams.Context] with this method: it would be ignored.
func (a *Client) GetEffectiveEntitlementsContext(ctx context.Context, params *GetEffectiveEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEffectiveEntitlementsOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewGetEffectiveEntitlementsParams()
	}

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

// GetEntitlements lists tenant or user scoped explicit grants.
//
// 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.GetEntitlementsContext] instead.
func (a *Client) GetEntitlements(params *GetEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEntitlementsOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// GetEntitlementsContext lists tenant or user scoped explicit grants.
//
// Do not use the deprecated [GetEntitlementsParams.Context] with this method: it would be ignored.
func (a *Client) GetEntitlementsContext(ctx context.Context, params *GetEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEntitlementsOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewGetEntitlementsParams()
	}

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

// GetSubscriptions lists tenant scoped subscriptions.
//
// 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.GetSubscriptionsContext] instead.
func (a *Client) GetSubscriptions(params *GetSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetSubscriptionsOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// GetSubscriptionsContext lists tenant scoped subscriptions.
//
// Do not use the deprecated [GetSubscriptionsParams.Context] with this method: it would be ignored.
func (a *Client) GetSubscriptionsContext(ctx context.Context, params *GetSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetSubscriptionsOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewGetSubscriptionsParams()
	}

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

// PostEntitlements creates explicit tenant or user grants.
//
// 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.PostEntitlementsContext] instead.
func (a *Client) PostEntitlements(params *PostEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostEntitlementsOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// PostEntitlementsContext creates explicit tenant or user grants.
//
// Do not use the deprecated [PostEntitlementsParams.Context] with this method: it would be ignored.
func (a *Client) PostEntitlementsContext(ctx context.Context, params *PostEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostEntitlementsOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewPostEntitlementsParams()
	}

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

// PostSubscriptions creates tenant subscriptions.
//
// 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.PostSubscriptionsContext] instead.
func (a *Client) PostSubscriptions(params *PostSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostSubscriptionsOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// PostSubscriptionsContext creates tenant subscriptions.
//
// Do not use the deprecated [PostSubscriptionsParams.Context] with this method: it would be ignored.
func (a *Client) PostSubscriptionsContext(ctx context.Context, params *PostSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostSubscriptionsOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewPostSubscriptionsParams()
	}

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

// PutEntitlements updates revoke or expire explicit grants.
//
// 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.PutEntitlementsContext] instead.
func (a *Client) PutEntitlements(params *PutEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutEntitlementsOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// PutEntitlementsContext updates revoke or expire explicit grants.
//
// Do not use the deprecated [PutEntitlementsParams.Context] with this method: it would be ignored.
func (a *Client) PutEntitlementsContext(ctx context.Context, params *PutEntitlementsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutEntitlementsOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewPutEntitlementsParams()
	}

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

// PutSubscriptions updates pause cancel or expire subscriptions.
//
// 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.PutSubscriptionsContext] instead.
func (a *Client) PutSubscriptions(params *PutSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutSubscriptionsOK, error) {
	var ctx context.Context
	if params.inner.ctx != nil {
		ctx = params.inner.ctx
	} else {
		ctx = context.Background()
	}

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

// PutSubscriptionsContext updates pause cancel or expire subscriptions.
//
// Do not use the deprecated [PutSubscriptionsParams.Context] with this method: it would be ignored.
func (a *Client) PutSubscriptionsContext(ctx context.Context, params *PutSubscriptionsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutSubscriptionsOK, error) {
	// NOTE: parameters are not validated before sending
	if params == nil {
		params = NewPutSubscriptionsParams()
	}

	op := &runtime.ClientOperation{
		ID:                 "putSubscriptions",
		Method:             "PUT",
		PathPattern:        "/subscriptions",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http"},
		Params:             params,
		Reader:             &PutSubscriptionsReader{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.(*PutSubscriptionsOK)
	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 putSubscriptions: 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 [PortalAccessParams].
	ctx context.Context
}
