// Code generated by Fern. DO NOT EDIT.

package customdomains

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,
			},
		),
	}
}

// Retrieve details on <a href="https://auth0.com/docs/custom-domains">custom domains</a>.
func (c *Client) List(
	ctx context.Context,
	opts ...option.RequestOption,
) (management.ListCustomDomainsResponseContent, error) {
	response, err := c.WithRawResponse.List(
		ctx,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Create a new custom domain.
//
// Note: The custom domain will need to be verified before it will accept
// requests.
//
// Optional attributes that can be updated:
//
// - custom_client_ip_header
// - tls_policy
//
// TLS Policies:
//
// - recommended - for modern usage this includes TLS 1.2 only
func (c *Client) Create(
	ctx context.Context,
	request *management.CreateCustomDomainRequestContent,
	opts ...option.RequestOption,
) (*management.CreateCustomDomainResponseContent, error) {
	response, err := c.WithRawResponse.Create(
		ctx,
		request,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Retrieve a custom domain configuration and status.
func (c *Client) Get(
	ctx context.Context,
	// ID of the custom domain to retrieve.
	id string,
	opts ...option.RequestOption,
) (*management.GetCustomDomainResponseContent, error) {
	response, err := c.WithRawResponse.Get(
		ctx,
		id,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Delete a custom domain and stop serving requests for it.
func (c *Client) Delete(
	ctx context.Context,
	// ID of the custom domain to delete.
	id string,
	opts ...option.RequestOption,
) error {
	_, err := c.WithRawResponse.Delete(
		ctx,
		id,
		opts...,
	)
	if err != nil {
		return err
	}
	return nil
}

// Update a custom domain.
//
// These are the attributes that can be updated:
//
// - custom_client_ip_header
// - tls_policy
//
// <h5>Updating CUSTOM_CLIENT_IP_HEADER for a custom domain</h5>To update the <code>custom_client_ip_header</code> for a domain, the body to
// send should be:
// <pre><code>{ "custom_client_ip_header": "cf-connecting-ip" }</code></pre>
//
// <h5>Updating TLS_POLICY for a custom domain</h5>To update the <code>tls_policy</code> for a domain, the body to send should be:
// <pre><code>{ "tls_policy": "recommended" }</code></pre>
//
// TLS Policies:
//
// - recommended - for modern usage this includes TLS 1.2 only
//
// Some considerations:
//
// - The TLS ciphers and protocols available in each TLS policy follow industry recommendations, and may be updated occasionally.
// - The <code>compatible</code> TLS policy is no longer supported.
func (c *Client) Update(
	ctx context.Context,
	// The id of the custom domain to update
	id string,
	request *management.UpdateCustomDomainRequestContent,
	opts ...option.RequestOption,
) (*management.UpdateCustomDomainResponseContent, error) {
	response, err := c.WithRawResponse.Update(
		ctx,
		id,
		request,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Run the test process on a custom domain.
func (c *Client) Test(
	ctx context.Context,
	// ID of the custom domain to test.
	id string,
	opts ...option.RequestOption,
) (*management.TestCustomDomainResponseContent, error) {
	response, err := c.WithRawResponse.Test(
		ctx,
		id,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Run the verification process on a custom domain.
//
// Note: Check the <code>status</code> field to see its verification status. Once verification is complete, it may take up to 10 minutes before the custom domain can start accepting requests.
//
// For <code>self_managed_certs</code>, when the custom domain is verified for the first time, the response will also include the <code>cname_api_key</code> which you will need to configure your proxy. This key must be kept secret, and is used to validate the proxy requests.
//
// <a href="https://auth0.com/docs/custom-domains#step-2-verify-ownership">Learn more</a> about verifying custom domains that use Auth0 Managed certificates.
// <a href="https://auth0.com/docs/custom-domains/self-managed-certificates#step-2-verify-ownership">Learn more</a> about verifying custom domains that use Self Managed certificates.
func (c *Client) Verify(
	ctx context.Context,
	// ID of the custom domain to verify.
	id string,
	opts ...option.RequestOption,
) (*management.VerifyCustomDomainResponseContent, error) {
	response, err := c.WithRawResponse.Verify(
		ctx,
		id,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}
