// Code generated by django-cfg centrifugo codegen. DO NOT EDIT.

package {{ package_name }}

import (
	"context"
	"time"
)

// APIClient is a thin wrapper over CentrifugoRPCClient with typed methods.
type APIClient struct {
	rpc *CentrifugoRPCClient
}

// NewAPIClient creates a new typed API client.
//
// Args:
//   - url: Centrifugo WebSocket URL
//   - token: JWT token for authentication
//   - userID: User ID for reply channel
//
// Example:
//
//	client := NewAPIClient("ws://localhost:8000/connection/websocket", token, "user123")
//	if err := client.Connect(ctx); err != nil {
//	    log.Fatal(err)
//	}
//	defer client.Disconnect()
func NewAPIClient(url, token, userID string) *APIClient {
	return &APIClient{
		rpc: NewCentrifugoRPCClient(url, token, userID, 30*time.Second),
	}
}

// Connect establishes connection to Centrifugo.
func (api *APIClient) Connect(ctx context.Context) error {
	return api.rpc.Connect(ctx)
}

// Disconnect closes the connection.
func (api *APIClient) Disconnect() error {
	return api.rpc.Disconnect()
}

{% for method in methods %}
// {{ method.name_go }}{% if method.docstring %} {{ method.docstring.split('\n')[0] }}{% endif %}

{% if method.docstring and method.docstring.split('\n')|length > 1 %}
{% for line in method.docstring.split('\n')[1:] %}
{% if line.strip() %}
// {{ line.strip() }}
{% endif %}
{% endfor %}
{% endif %}
func (api *APIClient) {{ method.name_go }}(ctx context.Context, params {{ method.param_type }}) (*{{ method.return_type }}, error) {
	var result {{ method.return_type }}
	err := api.rpc.Call(ctx, "{{ method.name }}", params, &result)
	if err != nil {
		return nil, err
	}
	return &result, nil
}

{% endfor %}
