package config

import (
	"os"
	"path/filepath"
	"strings"
	"testing"
)

func TestOutboxWorkerAppCodesNormalizeForStagedReplay(t *testing.T) {
	path := filepath.Join(t.TempDir(), "config.yaml")
	if err := os.WriteFile(path, []byte("outbox_worker:\n  app_codes: [' LALU ', fami, HUWAA, fami]\n"), 0o600); err != nil {
		t.Fatalf("write config: %v", err)
	}
	cfg, err := Load(path)
	if err != nil {
		t.Fatalf("load staged outbox config: %v", err)
	}
	if got := strings.Join(cfg.OutboxWorker.AppCodes, ","); got != "lalu,fami,huwaa" {
		t.Fatalf("normalized outbox app_codes = %q", got)
	}
}

func TestLocalOutboxWorkerEmptyAppCodesUsesDiscovery(t *testing.T) {
	cfg, err := Load("../../configs/config.yaml")
	if err != nil {
		t.Fatalf("load local config: %v", err)
	}
	if len(cfg.OutboxWorker.AppCodes) != 0 {
		t.Fatalf("local empty app_codes must retain automatic discovery: %v", cfg.OutboxWorker.AppCodes)
	}
}
