package core

import (
	"os"

	"github.com/keepmind9/acp-sdk-go/client"
	"github.com/keepmind9/acp-sdk-go/transport"
)

// ConnectToAgent starts an agent subprocess and connects a client to it over stdio.
// It returns the Subprocess handle and the ClientSideConnection.
// The caller is responsible for calling Subprocess.Close() to shut down the agent.
func ConnectToAgent(impl client.Client, subprocess *transport.Subprocess) *client.ClientSideConnection {
	return client.NewClientSideConnection(impl, subprocess.Stdout, subprocess.Stdin)
}

// RunClient starts an ACP client over stdio, connecting to an agent on the other end.
// It reads JSON-RPC messages from os.Stdin and writes responses to os.Stdout.
func RunClient(impl client.Client) {
	conn := client.NewClientSideConnection(impl, os.Stdin, os.Stdout)
	conn.ReceiveLoop()
}
