// Command example demonstrates basic usage of the quicproquo Go SDK.
package main

import (
	"context"
	"fmt"
	"os"

	"quicproquo.dev/sdk/go/qpq"
)

func main() {
	addr := "127.0.0.1:5001"
	if len(os.Args) > 1 {
		addr = os.Args[1]
	}

	ctx := context.Background()

	client, err := qpq.Connect(ctx, qpq.Options{
		Addr:               addr,
		InsecureSkipVerify: true,
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "connect failed: %v\n", err)
		os.Exit(1)
	}
	defer client.Close()

	status, err := client.Health(ctx)
	if err != nil {
		fmt.Fprintf(os.Stderr, "health check failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Server health: %s\n", status)

	fmt.Println("\nUsage:")
	fmt.Println("  // Authenticate with a pre-existing session token")
	fmt.Println("  client.SetSessionToken(token)")
	fmt.Println()
	fmt.Println("  // Resolve a user's identity key")
	fmt.Println("  key, err := client.ResolveUser(ctx, \"alice\")")
	fmt.Println()
	fmt.Println("  // Create a DM channel")
	fmt.Println("  chID, wasNew, err := client.CreateChannel(ctx, peerKey)")
	fmt.Println()
	fmt.Println("  // Send a message")
	fmt.Println("  seq, err := client.Send(ctx, recipientKey, payload)")
	fmt.Println()
	fmt.Println("  // Receive messages")
	fmt.Println("  msgs, err := client.Receive(ctx, recipientKey)")
	fmt.Println()
	fmt.Println("  // Long-poll for messages (5 second timeout)")
	fmt.Println("  msgs, err := client.ReceiveWait(ctx, recipientKey, 5000)")
}
