// Package svix this file is @generated DO NOT EDIT
package internalapi

import (
	"context"

	"github.com/svix/svix-webhooks/go/internal"
	"github.com/svix/svix-webhooks/go/models"
)

type ManagementAuthentication struct {
	client *internal.SvixHttpClient
}

func newManagementAuthentication(client *internal.SvixHttpClient) ManagementAuthentication {
	return ManagementAuthentication{client}
}

type ManagementAuthenticationExpireApiTokenOptions struct {
	IdempotencyKey *string
}

type ManagementAuthenticationCreateApiTokenOptions struct {
	IdempotencyKey *string
}

// Expire the selected API Token.
func (managementAuthentication ManagementAuthentication) ExpireApiToken(
	ctx context.Context,
	envId string,
	keyId string,
	apiTokenExpireIn models.ApiTokenExpireIn,
	o *ManagementAuthenticationExpireApiTokenOptions,
) error {
	var err error
	pathMap := map[string]string{
		"env_id": envId,
		"key_id": keyId,
	}
	headerMap := map[string]string{}
	if o == nil {
		opts := ManagementAuthenticationExpireApiTokenOptions{}
		o = &opts
	}
	internal.SerializeParamToMap("idempotency-key", o.IdempotencyKey, headerMap, &err)
	if err != nil {
		return err
	}
	_, err = internal.ExecuteRequest[models.ApiTokenExpireIn, any](
		ctx,
		managementAuthentication.client,
		"POST",
		"/api/v1/management/authentication/{env_id}/api-token/{key_id}/expire",
		pathMap,
		nil,
		headerMap,
		&apiTokenExpireIn,
	)
	return err
}

// Patch an API token
func (managementAuthentication ManagementAuthentication) PatchApiToken(
	ctx context.Context,
	envId string,
	keyId string,
	apiTokenPatch models.ApiTokenPatch,
) (*models.ApiTokenCensoredOut, error) {
	pathMap := map[string]string{
		"env_id": envId,
		"key_id": keyId,
	}
	return internal.ExecuteRequest[models.ApiTokenPatch, models.ApiTokenCensoredOut](
		ctx,
		managementAuthentication.client,
		"PATCH",
		"/api/v1/management/authentication/{env_id}/api-token/{key_id}",
		pathMap,
		nil,
		nil,
		&apiTokenPatch,
	)
}

// Create a new API Token.
func (managementAuthentication ManagementAuthentication) CreateApiToken(
	ctx context.Context,
	envId string,
	apiTokenIn models.ApiTokenIn,
	o *ManagementAuthenticationCreateApiTokenOptions,
) (*models.ApiTokenOut, error) {
	var err error
	pathMap := map[string]string{
		"env_id": envId,
	}
	headerMap := map[string]string{}
	if o == nil {
		opts := ManagementAuthenticationCreateApiTokenOptions{}
		o = &opts
	}
	internal.SerializeParamToMap("idempotency-key", o.IdempotencyKey, headerMap, &err)
	if err != nil {
		return nil, err
	}
	return internal.ExecuteRequest[models.ApiTokenIn, models.ApiTokenOut](
		ctx,
		managementAuthentication.client,
		"POST",
		"/api/v1/management/authentication/{env_id}/api-token",
		pathMap,
		nil,
		headerMap,
		&apiTokenIn,
	)
}
