package cmd

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/require"

	"github.com/tidbcloud/AgentTeam/desktop/internal/agentview"
)

func TestPrintAgentListTableIncludesNameAndStatus(t *testing.T) {
	output := captureStdout(t, func() {
		require.NoError(t, printAgentListTable([]agentview.Snapshot{{
			ID: "agt_123", Name: "researcher", Status: "running", Runtime: "codex",
			Model: "gpt-5.6", Source: "agentteam:srv_1",
		}}))
	})

	lines := strings.Split(strings.TrimSpace(output), "\n")
	require.Len(t, lines, 2)
	require.Equal(t, []string{"ID", "NAME", "STATUS", "RUNTIME", "MODEL", "SOURCE"}, strings.Fields(lines[0]))
	require.Equal(t, []string{"agt_123", "researcher", "running", "codex", "gpt-5.6", "agentteam:srv_1"}, strings.Fields(lines[1]))
}

func TestPrintAgentListJSONIncludesNameAndStatus(t *testing.T) {
	output := captureStdout(t, func() {
		require.NoError(t, printAgentListJSON([]agentview.Snapshot{{
			ID: "agt_123", Name: "researcher", Status: "running", Runtime: "codex",
		}}, false))
	})

	require.JSONEq(t, `[{
		"id":"agt_123",
		"name":"researcher",
		"status":"running",
		"runtime":"codex"
	}]`, output)
}
