// Code generated by Fern. DO NOT EDIT.

package credentials

import (
	context "context"
	management "github.com/auth0/go-auth0/v2/management"
	core "github.com/auth0/go-auth0/v2/management/core"
	internal "github.com/auth0/go-auth0/v2/management/internal"
	option "github.com/auth0/go-auth0/v2/management/option"
)

type Client struct {
	WithRawResponse *RawClient

	options *core.RequestOptions
	baseURL string
	caller  *internal.Caller
}

func NewClient(options *core.RequestOptions) *Client {
	return &Client{
		WithRawResponse: NewRawClient(options),
		options:         options,
		baseURL:         options.BaseURL,
		caller: internal.NewCaller(
			&internal.CallerParams{
				Client:      options.HTTPClient,
				MaxAttempts: options.MaxAttempts,
			},
		),
	}
}

// Get the details of a client credential.
//
// <b>Important</b>: To enable credentials to be used for a client authentication method, set the <code>client_authentication_methods</code> property on the client. To enable credentials to be used for JWT-Secured Authorization requests set the <code>signed_request_object</code> property on the client.
func (c *Client) List(
	ctx context.Context,
	// ID of the client.
	clientID string,
	opts ...option.RequestOption,
) ([]*management.ClientCredential, error) {
	response, err := c.WithRawResponse.List(
		ctx,
		clientID,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Create a client credential associated to your application. Credentials can be used to configure Private Key JWT and mTLS authentication methods, as well as for JWT-secured Authorization requests.
//
// <h5>Public Key</h5>Public Key credentials can be used to set up Private Key JWT client authentication and JWT-secured Authorization requests.
//
//	Sample: <pre><code>{
//	  "credential_type": "public_key",
//	  "name": "string",
//	  "pem": "string",
//	  "alg": "RS256",
//	  "parse_expiry_from_cert": false,
//	  "expires_at": "2022-12-31T23:59:59Z"
//	}</code></pre>
//
// <h5>Certificate (CA-signed & self-signed)</h5>Certificate credentials can be used to set up mTLS client authentication. CA-signed certificates can be configured either with a signed certificate or with just the certificate Subject DN.
//
//	CA-signed Certificate Sample (pem): <pre><code>{
//	  "credential_type": "x509_cert",
//	  "name": "string",
//	  "pem": "string"
//	}</code></pre>CA-signed Certificate Sample (subject_dn): <pre><code>{
//
//	  "credential_type": "cert_subject_dn",
//	  "name": "string",
//	  "subject_dn": "string"
//	}</code></pre>Self-signed Certificate Sample: <pre><code>{
//
//	  "credential_type": "cert_subject_dn",
//	  "name": "string",
//	  "pem": "string"
//	}</code></pre>
//
// The credential will be created but not yet enabled for use until you set the corresponding properties in the client:
// <ul>
//
//	<li>To enable the credential for Private Key JWT or mTLS authentication methods, set the <code>client_authentication_methods</code> property on the client. For more information, read <a href="https://auth0.com/docs/get-started/applications/configure-private-key-jwt">Configure Private Key JWT Authentication</a> and <a href="https://auth0.com/docs/get-started/applications/configure-mtls">Configure mTLS Authentication</a></li>
//	<li>To enable the credential for JWT-secured Authorization requests, set the <code>signed_request_object</code>property on the client. For more information, read <a href="https://auth0.com/docs/get-started/applications/configure-jar">Configure JWT-secured Authorization Requests (JAR)</a></li>
//
// </ul>
func (c *Client) Create(
	ctx context.Context,
	// ID of the client.
	clientID string,
	request *management.PostClientCredentialRequestContent,
	opts ...option.RequestOption,
) (*management.PostClientCredentialResponseContent, error) {
	response, err := c.WithRawResponse.Create(
		ctx,
		clientID,
		request,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Get the details of a client credential.
//
// <b>Important</b>: To enable credentials to be used for a client authentication method, set the <code>client_authentication_methods</code> property on the client. To enable credentials to be used for JWT-Secured Authorization requests set the <code>signed_request_object</code> property on the client.
func (c *Client) Get(
	ctx context.Context,
	// ID of the client.
	clientID string,
	// ID of the credential.
	credentialID string,
	opts ...option.RequestOption,
) (*management.GetClientCredentialResponseContent, error) {
	response, err := c.WithRawResponse.Get(
		ctx,
		clientID,
		credentialID,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Delete a client credential you previously created. May be enabled or disabled. For more information, read <a href="https://www.auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow">Client Credential Flow</a>.
func (c *Client) Delete(
	ctx context.Context,
	// ID of the client.
	clientID string,
	// ID of the credential to delete.
	credentialID string,
	opts ...option.RequestOption,
) error {
	_, err := c.WithRawResponse.Delete(
		ctx,
		clientID,
		credentialID,
		opts...,
	)
	if err != nil {
		return err
	}
	return nil
}

// Change a client credential you previously created. May be enabled or disabled. For more information, read <a href="https://www.auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow">Client Credential Flow</a>.
func (c *Client) Update(
	ctx context.Context,
	// ID of the client.
	clientID string,
	// ID of the credential.
	credentialID string,
	request *management.PatchClientCredentialRequestContent,
	opts ...option.RequestOption,
) (*management.PatchClientCredentialResponseContent, error) {
	response, err := c.WithRawResponse.Update(
		ctx,
		clientID,
		credentialID,
		request,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}
