// Code generated by Fern. DO NOT EDIT.

package userattributeprofiles

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"
	http "net/http"
)

type RawClient struct {
	baseURL string
	caller  *internal.Caller
	options *core.RequestOptions
}

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

func (r *RawClient) Create(
	ctx context.Context,
	request *management.CreateUserAttributeProfileRequestContent,
	opts ...option.RequestOption,
) (*core.Response[*management.CreateUserAttributeProfileResponseContent], error) {
	options := core.NewRequestOptions(opts...)
	baseURL := internal.ResolveBaseURL(
		options.BaseURL,
		r.baseURL,
		"https://%7BTENANT%7D.auth0.com/api/v2",
	)
	endpointURL := baseURL + "/user-attribute-profiles"
	headers := internal.MergeHeaders(
		r.options.ToHeader(),
		options.ToHeader(),
	)
	headers.Add("Content-Type", "application/json")
	var response *management.CreateUserAttributeProfileResponseContent
	raw, err := r.caller.Call(
		ctx,
		&internal.CallParams{
			URL:             endpointURL,
			Method:          http.MethodPost,
			Headers:         headers,
			MaxAttempts:     options.MaxAttempts,
			BodyProperties:  options.BodyProperties,
			QueryParameters: options.QueryParameters,
			Client:          options.HTTPClient,
			Request:         request,
			Response:        &response,
			ErrorDecoder:    internal.NewErrorDecoder(management.ErrorCodes),
		},
	)
	if err != nil {
		return nil, err
	}
	return &core.Response[*management.CreateUserAttributeProfileResponseContent]{
		StatusCode: raw.StatusCode,
		Header:     raw.Header,
		Body:       response,
	}, nil
}

func (r *RawClient) ListTemplates(
	ctx context.Context,
	opts ...option.RequestOption,
) (*core.Response[*management.ListUserAttributeProfileTemplateResponseContent], error) {
	options := core.NewRequestOptions(opts...)
	baseURL := internal.ResolveBaseURL(
		options.BaseURL,
		r.baseURL,
		"https://%7BTENANT%7D.auth0.com/api/v2",
	)
	endpointURL := baseURL + "/user-attribute-profiles/templates"
	headers := internal.MergeHeaders(
		r.options.ToHeader(),
		options.ToHeader(),
	)
	var response *management.ListUserAttributeProfileTemplateResponseContent
	raw, err := r.caller.Call(
		ctx,
		&internal.CallParams{
			URL:             endpointURL,
			Method:          http.MethodGet,
			Headers:         headers,
			MaxAttempts:     options.MaxAttempts,
			BodyProperties:  options.BodyProperties,
			QueryParameters: options.QueryParameters,
			Client:          options.HTTPClient,
			Response:        &response,
			ErrorDecoder:    internal.NewErrorDecoder(management.ErrorCodes),
		},
	)
	if err != nil {
		return nil, err
	}
	return &core.Response[*management.ListUserAttributeProfileTemplateResponseContent]{
		StatusCode: raw.StatusCode,
		Header:     raw.Header,
		Body:       response,
	}, nil
}

func (r *RawClient) GetTemplate(
	ctx context.Context,
	// ID of the user-attribute-profile-template to retrieve.
	id string,
	opts ...option.RequestOption,
) (*core.Response[*management.GetUserAttributeProfileTemplateResponseContent], error) {
	options := core.NewRequestOptions(opts...)
	baseURL := internal.ResolveBaseURL(
		options.BaseURL,
		r.baseURL,
		"https://%7BTENANT%7D.auth0.com/api/v2",
	)
	endpointURL := internal.EncodeURL(
		baseURL+"/user-attribute-profiles/templates/%v",
		id,
	)
	headers := internal.MergeHeaders(
		r.options.ToHeader(),
		options.ToHeader(),
	)
	var response *management.GetUserAttributeProfileTemplateResponseContent
	raw, err := r.caller.Call(
		ctx,
		&internal.CallParams{
			URL:             endpointURL,
			Method:          http.MethodGet,
			Headers:         headers,
			MaxAttempts:     options.MaxAttempts,
			BodyProperties:  options.BodyProperties,
			QueryParameters: options.QueryParameters,
			Client:          options.HTTPClient,
			Response:        &response,
			ErrorDecoder:    internal.NewErrorDecoder(management.ErrorCodes),
		},
	)
	if err != nil {
		return nil, err
	}
	return &core.Response[*management.GetUserAttributeProfileTemplateResponseContent]{
		StatusCode: raw.StatusCode,
		Header:     raw.Header,
		Body:       response,
	}, nil
}

func (r *RawClient) Get(
	ctx context.Context,
	// ID of the user-attribute-profile to retrieve.
	id string,
	opts ...option.RequestOption,
) (*core.Response[*management.GetUserAttributeProfileResponseContent], error) {
	options := core.NewRequestOptions(opts...)
	baseURL := internal.ResolveBaseURL(
		options.BaseURL,
		r.baseURL,
		"https://%7BTENANT%7D.auth0.com/api/v2",
	)
	endpointURL := internal.EncodeURL(
		baseURL+"/user-attribute-profiles/%v",
		id,
	)
	headers := internal.MergeHeaders(
		r.options.ToHeader(),
		options.ToHeader(),
	)
	var response *management.GetUserAttributeProfileResponseContent
	raw, err := r.caller.Call(
		ctx,
		&internal.CallParams{
			URL:             endpointURL,
			Method:          http.MethodGet,
			Headers:         headers,
			MaxAttempts:     options.MaxAttempts,
			BodyProperties:  options.BodyProperties,
			QueryParameters: options.QueryParameters,
			Client:          options.HTTPClient,
			Response:        &response,
			ErrorDecoder:    internal.NewErrorDecoder(management.ErrorCodes),
		},
	)
	if err != nil {
		return nil, err
	}
	return &core.Response[*management.GetUserAttributeProfileResponseContent]{
		StatusCode: raw.StatusCode,
		Header:     raw.Header,
		Body:       response,
	}, nil
}

func (r *RawClient) Delete(
	ctx context.Context,
	// ID of the user-attribute-profile to delete.
	id string,
	opts ...option.RequestOption,
) (*core.Response[any], error) {
	options := core.NewRequestOptions(opts...)
	baseURL := internal.ResolveBaseURL(
		options.BaseURL,
		r.baseURL,
		"https://%7BTENANT%7D.auth0.com/api/v2",
	)
	endpointURL := internal.EncodeURL(
		baseURL+"/user-attribute-profiles/%v",
		id,
	)
	headers := internal.MergeHeaders(
		r.options.ToHeader(),
		options.ToHeader(),
	)
	raw, err := r.caller.Call(
		ctx,
		&internal.CallParams{
			URL:             endpointURL,
			Method:          http.MethodDelete,
			Headers:         headers,
			MaxAttempts:     options.MaxAttempts,
			BodyProperties:  options.BodyProperties,
			QueryParameters: options.QueryParameters,
			Client:          options.HTTPClient,
			ErrorDecoder:    internal.NewErrorDecoder(management.ErrorCodes),
		},
	)
	if err != nil {
		return nil, err
	}
	return &core.Response[any]{
		StatusCode: raw.StatusCode,
		Header:     raw.Header,
		Body:       nil,
	}, nil
}

func (r *RawClient) Update(
	ctx context.Context,
	// ID of the user attribute profile to update.
	id string,
	request *management.UpdateUserAttributeProfileRequestContent,
	opts ...option.RequestOption,
) (*core.Response[*management.UpdateUserAttributeProfileResponseContent], error) {
	options := core.NewRequestOptions(opts...)
	baseURL := internal.ResolveBaseURL(
		options.BaseURL,
		r.baseURL,
		"https://%7BTENANT%7D.auth0.com/api/v2",
	)
	endpointURL := internal.EncodeURL(
		baseURL+"/user-attribute-profiles/%v",
		id,
	)
	headers := internal.MergeHeaders(
		r.options.ToHeader(),
		options.ToHeader(),
	)
	headers.Add("Content-Type", "application/json")
	var response *management.UpdateUserAttributeProfileResponseContent
	raw, err := r.caller.Call(
		ctx,
		&internal.CallParams{
			URL:             endpointURL,
			Method:          http.MethodPatch,
			Headers:         headers,
			MaxAttempts:     options.MaxAttempts,
			BodyProperties:  options.BodyProperties,
			QueryParameters: options.QueryParameters,
			Client:          options.HTTPClient,
			Request:         request,
			Response:        &response,
			ErrorDecoder:    internal.NewErrorDecoder(management.ErrorCodes),
		},
	)
	if err != nil {
		return nil, err
	}
	return &core.Response[*management.UpdateUserAttributeProfileResponseContent]{
		StatusCode: raw.StatusCode,
		Header:     raw.Header,
		Body:       response,
	}, nil
}
