package dryrun

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

	cfgpkg "github.com/jan/fm-rds-tx/internal/config"
)

func TestGenerate(t *testing.T) {
	cfg := cfgpkg.Default()
	frame := Generate(cfg)
	if frame.Mode != "dry-run" { t.Fatalf("mode: %s", frame.Mode) }
	if len(frame.PreviewSamples) != 16 { t.Fatal("preview length") }
	if frame.Source != "tones" { t.Fatal("source") }
	if frame.PreEmphasisTauUS != 50 { t.Fatal("preemph") }
	if !frame.FMModulation { t.Fatal("fm mod") }
	if frame.DeviceRate != float64(cfg.FM.CompositeRateHz) { t.Fatal("device rate") }
}

func TestWriteJSONFile(t *testing.T) {
	dir := t.TempDir()
	out := filepath.Join(dir, "frame.json")
	if err := WriteJSON(out, Generate(cfgpkg.Default())); err != nil { t.Fatal(err) }
	if _, err := os.Stat(out); err != nil { t.Fatal(err) }
}
