package ca_test

import (
	"context"
	"testing"
	"time"
)

// TestGetCtrl exercises GetCtrl across the native DBF types served by the mock,
// covering NativeCtrlType dispatch and the DBR_CTRL_* decoders.
func TestGetCtrl(t *testing.T) {
	srv := newTestServer(t)
	cli := newTestClient(t, srv)

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	t.Run("double", func(t *testing.T) {
		ci, err := cli.GetCtrl(ctx, "TEST:DOUBLE")
		if err != nil {
			t.Fatalf("GetCtrl: %v", err)
		}
		if ci.Double == nil {
			t.Fatal("expected Double ctrl info")
		}
	})

	t.Run("long", func(t *testing.T) {
		ci, err := cli.GetCtrl(ctx, "TEST:LONG")
		if err != nil {
			t.Fatalf("GetCtrl: %v", err)
		}
		if ci.Long == nil {
			t.Fatal("expected Long ctrl info")
		}
	})

	t.Run("enum", func(t *testing.T) {
		ci, err := cli.GetCtrl(ctx, "TEST:ENUM")
		if err != nil {
			t.Fatalf("GetCtrl: %v", err)
		}
		if ci.Enum == nil {
			t.Fatal("expected Enum ctrl info")
		}
	})

	t.Run("string", func(t *testing.T) {
		ci, err := cli.GetCtrl(ctx, "TEST:STRING")
		if err != nil {
			t.Fatalf("GetCtrl: %v", err)
		}
		if ci.Str == nil {
			t.Fatal("expected Str ctrl info")
		}
	})
}
