package protocol

import (
	"encoding/json"
	"testing"
)

func decodeFrame(t *testing.T, b []byte) map[string]any {
	t.Helper()
	var m map[string]any
	if err := json.Unmarshal(b, &m); err != nil {
		t.Fatalf("unmarshal: %v", err)
	}
	return m
}

func TestStartSessionOmitsEmptyInput(t *testing.T) {
	m := decodeFrame(t, StartSession("healthcheck", ""))
	if m["workflowId"] != "healthcheck" {
		t.Fatalf("unexpected frame: %+v", m)
	}
	if _, present := m["input"]; present {
		t.Fatalf("empty input must be omitted, got: %+v", m)
	}
}

func TestStartSessionCarriesIntent(t *testing.T) {
	m := decodeFrame(t, StartSession("role_pipeline", "add an auth layer to the account service"))
	if m["input"] != "add an auth layer to the account service" {
		t.Fatalf("intent not carried: %+v", m)
	}
}
