// Package apigen provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT.
package apigen

import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"net/url"
	"strings"
	"time"

	"github.com/gofiber/fiber/v2"
	"github.com/oapi-codegen/runtime"
)

const (
	BearerAuthScopes = "BearerAuth.Scopes"
)

// Defines values for CredentialsTokenType.
const (
	Bearer CredentialsTokenType = "Bearer"
)

// Defines values for EventSpecType.
const (
	TaskCompleted EventSpecType = "TaskCompleted"
	TaskError     EventSpecType = "TaskError"
)

// Defines values for TaskEvents.
const (
	OnFailed TaskEvents = "onFailed"
)

// Defines values for TaskStatus.
const (
	Completed TaskStatus = "completed"
	Failed    TaskStatus = "failed"
	Paused    TaskStatus = "paused"
	Pending   TaskStatus = "pending"
)

// Credentials defines model for Credentials.
type Credentials struct {
	// AccessToken JWT access token
	AccessToken string `json:"accessToken"`

	// RefreshToken JWT refresh token for obtaining new access tokens
	RefreshToken string `json:"refreshToken"`

	// TokenType Token type
	TokenType CredentialsTokenType `json:"tokenType"`
}

// CredentialsTokenType Token type
type CredentialsTokenType string

// Event defines model for Event.
type Event struct {
	ID        int32     `json:"ID"`
	CreatedAt time.Time `json:"createdAt"`
	Spec      EventSpec `json:"spec"`
}

// EventSpec defines model for EventSpec.
type EventSpec struct {
	TaskCompleted *EventTaskCompleted `json:"taskCompleted,omitempty"`
	TaskError     *EventTaskError     `json:"taskError,omitempty"`
	Type          EventSpecType       `json:"type"`
}

// EventSpecType defines model for EventSpec.Type.
type EventSpecType string

// EventTaskCompleted defines model for EventTaskCompleted.
type EventTaskCompleted struct {
	TaskID int32 `json:"taskID"`
}

// EventTaskError defines model for EventTaskError.
type EventTaskError struct {
	Error  string `json:"error"`
	TaskID int32  `json:"taskID"`
}

// Org defines model for Org.
type Org struct {
	ID        int32     `json:"ID"`
	CreatedAt time.Time `json:"createdAt"`
	Name      string    `json:"name"`
	UpdatedAt time.Time `json:"updatedAt"`
}

// RefreshTokenRequest defines model for RefreshTokenRequest.
type RefreshTokenRequest struct {
	// RefreshToken Refresh token obtained from sign-in
	RefreshToken string `json:"refreshToken"`
}

// SignInRequest defines model for SignInRequest.
type SignInRequest struct {
	// Name User's name
	Name string `json:"name"`

	// Password User's password
	Password string `json:"password"`
}

// Task defines model for Task.
type Task struct {
	ID int32 `json:"ID"`

	// Attempts The number of times the task has been attempted
	Attempts   int32          `json:"attempts"`
	Attributes TaskAttributes `json:"attributes"`
	CreatedAt  time.Time      `json:"createdAt"`
	Events     []TaskEvents   `json:"events"`
	Spec       TaskSpec       `json:"spec"`
	StartedAt  *time.Time     `json:"startedAt,omitempty"`
	Status     TaskStatus     `json:"status"`

	// UniqueTag Unique tag of the task
	UniqueTag *string   `json:"uniqueTag,omitempty"`
	UpdatedAt time.Time `json:"updatedAt"`
}

// TaskEvents defines model for Task.Events.
type TaskEvents string

// TaskStatus defines model for Task.Status.
type TaskStatus string

// TaskAttributes defines model for TaskAttributes.
type TaskAttributes struct {
	Cronjob     *TaskCronjob     `json:"cronjob,omitempty"`
	RetryPolicy *TaskRetryPolicy `json:"retryPolicy,omitempty"`

	// Timeout Timeout of the task, a valid go time duration value e.g. 1h, 1d, 1w, 1m
	Timeout *string `json:"timeout,omitempty"`
}

// TaskCronjob defines model for TaskCronjob.
type TaskCronjob struct {
	CronExpression string `json:"cronExpression"`
}

// TaskRetryPolicy defines model for TaskRetryPolicy.
type TaskRetryPolicy struct {
	// Interval Interval of the retry policy, e.g. 1h, 1d, 1w, 1m
	Interval string `json:"interval"`

	// MaxAttempts Maximum number of attempts to retry the task, -1 means infinite retries
	MaxAttempts int32 `json:"maxAttempts"`
}

// TaskSpec defines model for TaskSpec.
type TaskSpec struct {
	// Payload The JSONB of the spec of the task
	Payload []byte `json:"payload"`
	Type    string `json:"type"`
}

// RefreshTokenJSONRequestBody defines body for RefreshToken for application/json ContentType.
type RefreshTokenJSONRequestBody = RefreshTokenRequest

// SignInJSONRequestBody defines body for SignIn for application/json ContentType.
type SignInJSONRequestBody = SignInRequest

// RequestEditorFn  is the function signature for the RequestEditor callback function
type RequestEditorFn func(ctx context.Context, req *http.Request) error

// Doer performs HTTP requests.
//
// The standard http.Client implements this interface.
type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

// Client which conforms to the OpenAPI3 specification for this service.
type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

// ClientOption allows setting custom parameters during construction
type ClientOption func(*Client) error

// Creates a new Client, with reasonable defaults
func NewClient(server string, opts ...ClientOption) (*Client, error) {
	// create a client with sane default values
	client := Client{
		Server: server,
	}
	// mutate client and add all optional params
	for _, o := range opts {
		if err := o(&client); err != nil {
			return nil, err
		}
	}
	// ensure the server URL always has a trailing slash
	if !strings.HasSuffix(client.Server, "/") {
		client.Server += "/"
	}
	// create httpClient, if not already present
	if client.Client == nil {
		client.Client = &http.Client{}
	}
	return &client, nil
}

// WithHTTPClient allows overriding the default Doer, which is
// automatically created using http.Client. This is useful for tests.
func WithHTTPClient(doer HttpRequestDoer) ClientOption {
	return func(c *Client) error {
		c.Client = doer
		return nil
	}
}

// WithRequestEditorFn allows setting up a callback function, which will be
// called right before sending the request. This can be used to mutate the request.
func WithRequestEditorFn(fn RequestEditorFn) ClientOption {
	return func(c *Client) error {
		c.RequestEditors = append(c.RequestEditors, fn)
		return nil
	}
}

// The interface specification for the client above.
type ClientInterface interface {
	// RefreshTokenWithBody request with any body
	RefreshTokenWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	RefreshToken(ctx context.Context, body RefreshTokenJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// SignInWithBody request with any body
	SignInWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	SignIn(ctx context.Context, body SignInJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// SignOut request
	SignOut(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// ListEvents request
	ListEvents(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// ListOrgs request
	ListOrgs(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// ListTasks request
	ListTasks(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// TryExecuteTask request
	TryExecuteTask(ctx context.Context, taskID int32, reqEditors ...RequestEditorFn) (*http.Response, error)
}

func (c *Client) RefreshTokenWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewRefreshTokenRequestWithBody(c.Server, contentType, body)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

func (c *Client) RefreshToken(ctx context.Context, body RefreshTokenJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewRefreshTokenRequest(c.Server, body)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

func (c *Client) SignInWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewSignInRequestWithBody(c.Server, contentType, body)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

func (c *Client) SignIn(ctx context.Context, body SignInJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewSignInRequest(c.Server, body)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

func (c *Client) SignOut(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewSignOutRequest(c.Server)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

func (c *Client) ListEvents(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewListEventsRequest(c.Server)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

func (c *Client) ListOrgs(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewListOrgsRequest(c.Server)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

func (c *Client) ListTasks(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewListTasksRequest(c.Server)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

func (c *Client) TryExecuteTask(ctx context.Context, taskID int32, reqEditors ...RequestEditorFn) (*http.Response, error) {
	req, err := NewTryExecuteTaskRequest(c.Server, taskID)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	if err := c.applyEditors(ctx, req, reqEditors); err != nil {
		return nil, err
	}
	return c.Client.Do(req)
}

// NewRefreshTokenRequest calls the generic RefreshToken builder with application/json body
func NewRefreshTokenRequest(server string, body RefreshTokenJSONRequestBody) (*http.Request, error) {
	var bodyReader io.Reader
	buf, err := json.Marshal(body)
	if err != nil {
		return nil, err
	}
	bodyReader = bytes.NewReader(buf)
	return NewRefreshTokenRequestWithBody(server, "application/json", bodyReader)
}

// NewRefreshTokenRequestWithBody generates requests for RefreshToken with any type of body
func NewRefreshTokenRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
	var err error

	serverURL, err := url.Parse(server)
	if err != nil {
		return nil, err
	}

	operationPath := fmt.Sprintf("/auth/refresh")
	if operationPath[0] == '/' {
		operationPath = "." + operationPath
	}

	queryURL, err := serverURL.Parse(operationPath)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("POST", queryURL.String(), body)
	if err != nil {
		return nil, err
	}

	req.Header.Add("Content-Type", contentType)

	return req, nil
}

// NewSignInRequest calls the generic SignIn builder with application/json body
func NewSignInRequest(server string, body SignInJSONRequestBody) (*http.Request, error) {
	var bodyReader io.Reader
	buf, err := json.Marshal(body)
	if err != nil {
		return nil, err
	}
	bodyReader = bytes.NewReader(buf)
	return NewSignInRequestWithBody(server, "application/json", bodyReader)
}

// NewSignInRequestWithBody generates requests for SignIn with any type of body
func NewSignInRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
	var err error

	serverURL, err := url.Parse(server)
	if err != nil {
		return nil, err
	}

	operationPath := fmt.Sprintf("/auth/sign-in")
	if operationPath[0] == '/' {
		operationPath = "." + operationPath
	}

	queryURL, err := serverURL.Parse(operationPath)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("POST", queryURL.String(), body)
	if err != nil {
		return nil, err
	}

	req.Header.Add("Content-Type", contentType)

	return req, nil
}

// NewSignOutRequest generates requests for SignOut
func NewSignOutRequest(server string) (*http.Request, error) {
	var err error

	serverURL, err := url.Parse(server)
	if err != nil {
		return nil, err
	}

	operationPath := fmt.Sprintf("/auth/sign-out")
	if operationPath[0] == '/' {
		operationPath = "." + operationPath
	}

	queryURL, err := serverURL.Parse(operationPath)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("POST", queryURL.String(), nil)
	if err != nil {
		return nil, err
	}

	return req, nil
}

// NewListEventsRequest generates requests for ListEvents
func NewListEventsRequest(server string) (*http.Request, error) {
	var err error

	serverURL, err := url.Parse(server)
	if err != nil {
		return nil, err
	}

	operationPath := fmt.Sprintf("/events")
	if operationPath[0] == '/' {
		operationPath = "." + operationPath
	}

	queryURL, err := serverURL.Parse(operationPath)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("GET", queryURL.String(), nil)
	if err != nil {
		return nil, err
	}

	return req, nil
}

// NewListOrgsRequest generates requests for ListOrgs
func NewListOrgsRequest(server string) (*http.Request, error) {
	var err error

	serverURL, err := url.Parse(server)
	if err != nil {
		return nil, err
	}

	operationPath := fmt.Sprintf("/orgs")
	if operationPath[0] == '/' {
		operationPath = "." + operationPath
	}

	queryURL, err := serverURL.Parse(operationPath)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("GET", queryURL.String(), nil)
	if err != nil {
		return nil, err
	}

	return req, nil
}

// NewListTasksRequest generates requests for ListTasks
func NewListTasksRequest(server string) (*http.Request, error) {
	var err error

	serverURL, err := url.Parse(server)
	if err != nil {
		return nil, err
	}

	operationPath := fmt.Sprintf("/tasks")
	if operationPath[0] == '/' {
		operationPath = "." + operationPath
	}

	queryURL, err := serverURL.Parse(operationPath)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("GET", queryURL.String(), nil)
	if err != nil {
		return nil, err
	}

	return req, nil
}

// NewTryExecuteTaskRequest generates requests for TryExecuteTask
func NewTryExecuteTaskRequest(server string, taskID int32) (*http.Request, error) {
	var err error

	var pathParam0 string

	pathParam0, err = runtime.StyleParamWithLocation("simple", false, "taskID", runtime.ParamLocationPath, taskID)
	if err != nil {
		return nil, err
	}

	serverURL, err := url.Parse(server)
	if err != nil {
		return nil, err
	}

	operationPath := fmt.Sprintf("/tasks/%s/try-execute", pathParam0)
	if operationPath[0] == '/' {
		operationPath = "." + operationPath
	}

	queryURL, err := serverURL.Parse(operationPath)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("POST", queryURL.String(), nil)
	if err != nil {
		return nil, err
	}

	return req, nil
}

func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error {
	for _, r := range c.RequestEditors {
		if err := r(ctx, req); err != nil {
			return err
		}
	}
	for _, r := range additionalEditors {
		if err := r(ctx, req); err != nil {
			return err
		}
	}
	return nil
}

// ClientWithResponses builds on ClientInterface to offer response payloads
type ClientWithResponses struct {
	ClientInterface
}

// NewClientWithResponses creates a new ClientWithResponses, which wraps
// Client with return type handling
func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) {
	client, err := NewClient(server, opts...)
	if err != nil {
		return nil, err
	}
	return &ClientWithResponses{client}, nil
}

// WithBaseURL overrides the baseURL.
func WithBaseURL(baseURL string) ClientOption {
	return func(c *Client) error {
		newBaseURL, err := url.Parse(baseURL)
		if err != nil {
			return err
		}
		c.Server = newBaseURL.String()
		return nil
	}
}

// ClientWithResponsesInterface is the interface specification for the client with responses above.
type ClientWithResponsesInterface interface {
	// RefreshTokenWithBodyWithResponse request with any body
	RefreshTokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RefreshTokenResponse, error)

	RefreshTokenWithResponse(ctx context.Context, body RefreshTokenJSONRequestBody, reqEditors ...RequestEditorFn) (*RefreshTokenResponse, error)

	// SignInWithBodyWithResponse request with any body
	SignInWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SignInResponse, error)

	SignInWithResponse(ctx context.Context, body SignInJSONRequestBody, reqEditors ...RequestEditorFn) (*SignInResponse, error)

	// SignOutWithResponse request
	SignOutWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*SignOutResponse, error)

	// ListEventsWithResponse request
	ListEventsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListEventsResponse, error)

	// ListOrgsWithResponse request
	ListOrgsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListOrgsResponse, error)

	// ListTasksWithResponse request
	ListTasksWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListTasksResponse, error)

	// TryExecuteTaskWithResponse request
	TryExecuteTaskWithResponse(ctx context.Context, taskID int32, reqEditors ...RequestEditorFn) (*TryExecuteTaskResponse, error)
}

type RefreshTokenResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *Credentials
}

// Status returns HTTPResponse.Status
func (r RefreshTokenResponse) Status() string {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.Status
	}
	return http.StatusText(0)
}

// StatusCode returns HTTPResponse.StatusCode
func (r RefreshTokenResponse) StatusCode() int {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.StatusCode
	}
	return 0
}

type SignInResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *Credentials
}

// Status returns HTTPResponse.Status
func (r SignInResponse) Status() string {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.Status
	}
	return http.StatusText(0)
}

// StatusCode returns HTTPResponse.StatusCode
func (r SignInResponse) StatusCode() int {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.StatusCode
	}
	return 0
}

type SignOutResponse struct {
	Body         []byte
	HTTPResponse *http.Response
}

// Status returns HTTPResponse.Status
func (r SignOutResponse) Status() string {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.Status
	}
	return http.StatusText(0)
}

// StatusCode returns HTTPResponse.StatusCode
func (r SignOutResponse) StatusCode() int {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.StatusCode
	}
	return 0
}

type ListEventsResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *[]Event
}

// Status returns HTTPResponse.Status
func (r ListEventsResponse) Status() string {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.Status
	}
	return http.StatusText(0)
}

// StatusCode returns HTTPResponse.StatusCode
func (r ListEventsResponse) StatusCode() int {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.StatusCode
	}
	return 0
}

type ListOrgsResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *[]Org
}

// Status returns HTTPResponse.Status
func (r ListOrgsResponse) Status() string {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.Status
	}
	return http.StatusText(0)
}

// StatusCode returns HTTPResponse.StatusCode
func (r ListOrgsResponse) StatusCode() int {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.StatusCode
	}
	return 0
}

type ListTasksResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *[]Task
}

// Status returns HTTPResponse.Status
func (r ListTasksResponse) Status() string {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.Status
	}
	return http.StatusText(0)
}

// StatusCode returns HTTPResponse.StatusCode
func (r ListTasksResponse) StatusCode() int {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.StatusCode
	}
	return 0
}

type TryExecuteTaskResponse struct {
	Body         []byte
	HTTPResponse *http.Response
}

// Status returns HTTPResponse.Status
func (r TryExecuteTaskResponse) Status() string {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.Status
	}
	return http.StatusText(0)
}

// StatusCode returns HTTPResponse.StatusCode
func (r TryExecuteTaskResponse) StatusCode() int {
	if r.HTTPResponse != nil {
		return r.HTTPResponse.StatusCode
	}
	return 0
}

// RefreshTokenWithBodyWithResponse request with arbitrary body returning *RefreshTokenResponse
func (c *ClientWithResponses) RefreshTokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RefreshTokenResponse, error) {
	rsp, err := c.RefreshTokenWithBody(ctx, contentType, body, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseRefreshTokenResponse(rsp)
}

func (c *ClientWithResponses) RefreshTokenWithResponse(ctx context.Context, body RefreshTokenJSONRequestBody, reqEditors ...RequestEditorFn) (*RefreshTokenResponse, error) {
	rsp, err := c.RefreshToken(ctx, body, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseRefreshTokenResponse(rsp)
}

// SignInWithBodyWithResponse request with arbitrary body returning *SignInResponse
func (c *ClientWithResponses) SignInWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SignInResponse, error) {
	rsp, err := c.SignInWithBody(ctx, contentType, body, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseSignInResponse(rsp)
}

func (c *ClientWithResponses) SignInWithResponse(ctx context.Context, body SignInJSONRequestBody, reqEditors ...RequestEditorFn) (*SignInResponse, error) {
	rsp, err := c.SignIn(ctx, body, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseSignInResponse(rsp)
}

// SignOutWithResponse request returning *SignOutResponse
func (c *ClientWithResponses) SignOutWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*SignOutResponse, error) {
	rsp, err := c.SignOut(ctx, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseSignOutResponse(rsp)
}

// ListEventsWithResponse request returning *ListEventsResponse
func (c *ClientWithResponses) ListEventsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListEventsResponse, error) {
	rsp, err := c.ListEvents(ctx, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseListEventsResponse(rsp)
}

// ListOrgsWithResponse request returning *ListOrgsResponse
func (c *ClientWithResponses) ListOrgsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListOrgsResponse, error) {
	rsp, err := c.ListOrgs(ctx, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseListOrgsResponse(rsp)
}

// ListTasksWithResponse request returning *ListTasksResponse
func (c *ClientWithResponses) ListTasksWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ListTasksResponse, error) {
	rsp, err := c.ListTasks(ctx, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseListTasksResponse(rsp)
}

// TryExecuteTaskWithResponse request returning *TryExecuteTaskResponse
func (c *ClientWithResponses) TryExecuteTaskWithResponse(ctx context.Context, taskID int32, reqEditors ...RequestEditorFn) (*TryExecuteTaskResponse, error) {
	rsp, err := c.TryExecuteTask(ctx, taskID, reqEditors...)
	if err != nil {
		return nil, err
	}
	return ParseTryExecuteTaskResponse(rsp)
}

// ParseRefreshTokenResponse parses an HTTP response from a RefreshTokenWithResponse call
func ParseRefreshTokenResponse(rsp *http.Response) (*RefreshTokenResponse, error) {
	bodyBytes, err := io.ReadAll(rsp.Body)
	defer func() { _ = rsp.Body.Close() }()
	if err != nil {
		return nil, err
	}

	response := &RefreshTokenResponse{
		Body:         bodyBytes,
		HTTPResponse: rsp,
	}

	switch {
	case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
		var dest Credentials
		if err := json.Unmarshal(bodyBytes, &dest); err != nil {
			return nil, err
		}
		response.JSON200 = &dest

	}

	return response, nil
}

// ParseSignInResponse parses an HTTP response from a SignInWithResponse call
func ParseSignInResponse(rsp *http.Response) (*SignInResponse, error) {
	bodyBytes, err := io.ReadAll(rsp.Body)
	defer func() { _ = rsp.Body.Close() }()
	if err != nil {
		return nil, err
	}

	response := &SignInResponse{
		Body:         bodyBytes,
		HTTPResponse: rsp,
	}

	switch {
	case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
		var dest Credentials
		if err := json.Unmarshal(bodyBytes, &dest); err != nil {
			return nil, err
		}
		response.JSON200 = &dest

	}

	return response, nil
}

// ParseSignOutResponse parses an HTTP response from a SignOutWithResponse call
func ParseSignOutResponse(rsp *http.Response) (*SignOutResponse, error) {
	bodyBytes, err := io.ReadAll(rsp.Body)
	defer func() { _ = rsp.Body.Close() }()
	if err != nil {
		return nil, err
	}

	response := &SignOutResponse{
		Body:         bodyBytes,
		HTTPResponse: rsp,
	}

	return response, nil
}

// ParseListEventsResponse parses an HTTP response from a ListEventsWithResponse call
func ParseListEventsResponse(rsp *http.Response) (*ListEventsResponse, error) {
	bodyBytes, err := io.ReadAll(rsp.Body)
	defer func() { _ = rsp.Body.Close() }()
	if err != nil {
		return nil, err
	}

	response := &ListEventsResponse{
		Body:         bodyBytes,
		HTTPResponse: rsp,
	}

	switch {
	case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
		var dest []Event
		if err := json.Unmarshal(bodyBytes, &dest); err != nil {
			return nil, err
		}
		response.JSON200 = &dest

	}

	return response, nil
}

// ParseListOrgsResponse parses an HTTP response from a ListOrgsWithResponse call
func ParseListOrgsResponse(rsp *http.Response) (*ListOrgsResponse, error) {
	bodyBytes, err := io.ReadAll(rsp.Body)
	defer func() { _ = rsp.Body.Close() }()
	if err != nil {
		return nil, err
	}

	response := &ListOrgsResponse{
		Body:         bodyBytes,
		HTTPResponse: rsp,
	}

	switch {
	case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
		var dest []Org
		if err := json.Unmarshal(bodyBytes, &dest); err != nil {
			return nil, err
		}
		response.JSON200 = &dest

	}

	return response, nil
}

// ParseListTasksResponse parses an HTTP response from a ListTasksWithResponse call
func ParseListTasksResponse(rsp *http.Response) (*ListTasksResponse, error) {
	bodyBytes, err := io.ReadAll(rsp.Body)
	defer func() { _ = rsp.Body.Close() }()
	if err != nil {
		return nil, err
	}

	response := &ListTasksResponse{
		Body:         bodyBytes,
		HTTPResponse: rsp,
	}

	switch {
	case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
		var dest []Task
		if err := json.Unmarshal(bodyBytes, &dest); err != nil {
			return nil, err
		}
		response.JSON200 = &dest

	}

	return response, nil
}

// ParseTryExecuteTaskResponse parses an HTTP response from a TryExecuteTaskWithResponse call
func ParseTryExecuteTaskResponse(rsp *http.Response) (*TryExecuteTaskResponse, error) {
	bodyBytes, err := io.ReadAll(rsp.Body)
	defer func() { _ = rsp.Body.Close() }()
	if err != nil {
		return nil, err
	}

	response := &TryExecuteTaskResponse{
		Body:         bodyBytes,
		HTTPResponse: rsp,
	}

	return response, nil
}

// ServerInterface represents all server handlers.
type ServerInterface interface {
	// Refresh access token
	// (POST /auth/refresh)
	RefreshToken(c *fiber.Ctx) error
	// Sign in user
	// (POST /auth/sign-in)
	SignIn(c *fiber.Ctx) error
	// Sign out user
	// (POST /auth/sign-out)
	SignOut(c *fiber.Ctx) error
	// Get all events
	// (GET /events)
	ListEvents(c *fiber.Ctx) error
	// Get all organizations of which the user is a member
	// (GET /orgs)
	ListOrgs(c *fiber.Ctx) error
	// Get all tasks
	// (GET /tasks)
	ListTasks(c *fiber.Ctx) error
	// Try to execute a task
	// (POST /tasks/{taskID}/try-execute)
	TryExecuteTask(c *fiber.Ctx, taskID int32) error
}

// ServerInterfaceWrapper converts contexts to parameters.
type ServerInterfaceWrapper struct {
	Handler ServerInterface
}

type MiddlewareFunc fiber.Handler

// RefreshToken operation middleware
func (siw *ServerInterfaceWrapper) RefreshToken(c *fiber.Ctx) error {

	return siw.Handler.RefreshToken(c)
}

// SignIn operation middleware
func (siw *ServerInterfaceWrapper) SignIn(c *fiber.Ctx) error {

	return siw.Handler.SignIn(c)
}

// SignOut operation middleware
func (siw *ServerInterfaceWrapper) SignOut(c *fiber.Ctx) error {

	c.Context().SetUserValue(BearerAuthScopes, []string{})

	return siw.Handler.SignOut(c)
}

// ListEvents operation middleware
func (siw *ServerInterfaceWrapper) ListEvents(c *fiber.Ctx) error {

	c.Context().SetUserValue(BearerAuthScopes, []string{})

	return siw.Handler.ListEvents(c)
}

// ListOrgs operation middleware
func (siw *ServerInterfaceWrapper) ListOrgs(c *fiber.Ctx) error {

	c.Context().SetUserValue(BearerAuthScopes, []string{})

	return siw.Handler.ListOrgs(c)
}

// ListTasks operation middleware
func (siw *ServerInterfaceWrapper) ListTasks(c *fiber.Ctx) error {

	c.Context().SetUserValue(BearerAuthScopes, []string{})

	return siw.Handler.ListTasks(c)
}

// TryExecuteTask operation middleware
func (siw *ServerInterfaceWrapper) TryExecuteTask(c *fiber.Ctx) error {

	var err error

	// ------------- Path parameter "taskID" -------------
	var taskID int32

	err = runtime.BindStyledParameterWithOptions("simple", "taskID", c.Params("taskID"), &taskID, runtime.BindStyledParameterOptions{Explode: false, Required: true})
	if err != nil {
		return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter taskID: %w", err).Error())
	}

	c.Context().SetUserValue(BearerAuthScopes, []string{})

	return siw.Handler.TryExecuteTask(c, taskID)
}

// FiberServerOptions provides options for the Fiber server.
type FiberServerOptions struct {
	BaseURL     string
	Middlewares []MiddlewareFunc
}

// RegisterHandlers creates http.Handler with routing matching OpenAPI spec.
func RegisterHandlers(router fiber.Router, si ServerInterface) {
	RegisterHandlersWithOptions(router, si, FiberServerOptions{})
}

// RegisterHandlersWithOptions creates http.Handler with additional options
func RegisterHandlersWithOptions(router fiber.Router, si ServerInterface, options FiberServerOptions) {
	wrapper := ServerInterfaceWrapper{
		Handler: si,
	}

	for _, m := range options.Middlewares {
		router.Use(fiber.Handler(m))
	}

	router.Post(options.BaseURL+"/auth/refresh", wrapper.RefreshToken)

	router.Post(options.BaseURL+"/auth/sign-in", wrapper.SignIn)

	router.Post(options.BaseURL+"/auth/sign-out", wrapper.SignOut)

	router.Get(options.BaseURL+"/events", wrapper.ListEvents)

	router.Get(options.BaseURL+"/orgs", wrapper.ListOrgs)

	router.Get(options.BaseURL+"/tasks", wrapper.ListTasks)

	router.Post(options.BaseURL+"/tasks/:taskID/try-execute", wrapper.TryExecuteTask)

}
