package input_test

import (
	"context"
	"testing"

	edgeinput "iop/apps/edge/internal/input"
	edgeservice "iop/apps/edge/internal/service"
	"iop/packages/go/config"

	"go.uber.org/zap"
)

func newTestService() *edgeservice.Service {
	return edgeservice.New(nil, nil)
}

func TestManagerOwnsOpenAIAndA2AInputs(t *testing.T) {
	cfg := config.EdgeConfig{
		OpenAI: config.EdgeOpenAIConf{Enabled: false},
		A2A:    config.EdgeA2AConf{Enabled: false},
	}
	mgr := edgeinput.NewManager(cfg, newTestService(), zap.NewNop())
	if mgr == nil {
		t.Fatal("NewManager returned nil")
	}
	if mgr.OpenAI == nil {
		t.Fatal("Manager.OpenAI is nil")
	}
	if mgr.A2A == nil {
		t.Fatal("Manager.A2A is nil")
	}
}

func TestManagerStartStopDisabled(t *testing.T) {
	cfg := config.EdgeConfig{
		OpenAI: config.EdgeOpenAIConf{Enabled: false},
		A2A:    config.EdgeA2AConf{Enabled: false},
	}
	mgr := edgeinput.NewManager(cfg, newTestService(), zap.NewNop())
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	if err := mgr.Start(ctx); err != nil {
		t.Fatalf("Start disabled: %v", err)
	}
	if err := mgr.Stop(ctx); err != nil {
		t.Fatalf("Stop disabled: %v", err)
	}
}
