package loadsim

import (
	"testing"

	"lingniu-vehicle-ingest/go/vehicle-gateway/internal/protocol/gb32960"
	"lingniu-vehicle-ingest/go/vehicle-gateway/internal/protocol/jt808"
)

func TestFrameTemplateReturnsParsableJT808LocationFrame(t *testing.T) {
	frame, err := FrameTemplate(ProtocolJT808, "0200")
	if err != nil {
		t.Fatalf("FrameTemplate() error = %v", err)
	}

	frames, remainder, err := jt808.ExtractFrames(frame)
	if err != nil {
		t.Fatalf("ExtractFrames() error = %v", err)
	}
	if len(remainder) != 0 {
		t.Fatalf("remainder len = %d", len(remainder))
	}
	if len(frames) != 1 {
		t.Fatalf("frames len = %d", len(frames))
	}
	if _, err := jt808.ParseFrame(frames[0], 1782918600000, "127.0.0.1:808"); err != nil {
		t.Fatalf("ParseFrame() error = %v", err)
	}
}

func TestFrameTemplateReturnsParsableGB32960RealtimeFrame(t *testing.T) {
	frame, err := FrameTemplate(ProtocolGB32960, "realtime")
	if err != nil {
		t.Fatalf("FrameTemplate() error = %v", err)
	}

	frames, remainder, err := gb32960.ExtractFrames(frame)
	if err != nil {
		t.Fatalf("ExtractFrames() error = %v", err)
	}
	if len(remainder) != 0 {
		t.Fatalf("remainder len = %d", len(remainder))
	}
	if len(frames) != 1 {
		t.Fatalf("frames len = %d", len(frames))
	}
	if _, err := gb32960.ParseFrame(frames[0], 1782918600000, "127.0.0.1:32960"); err != nil {
		t.Fatalf("ParseFrame() error = %v", err)
	}
}
