package common_test

import (
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/can-go/pkg/descriptor"
	"github.com/stretchr/testify/assert"
)

func TestCopySignal(t *testing.T) {
	expOut := common.SignalDesc{
		Name:             "TBOX_RemPassSeatHeatgCmd",
		Start:            23,
		Length:           3,
		IsBigEndian:      true,
		IsSigned:         false,
		IsMultiplexer:    false,
		IsMultiplexed:    false,
		MultiplexerValue: 0,
		Offset:           0,
		Scale:            1,
		Min:              0,
		Max:              7,
		Unit:             "",
		Description:      "Remote passenger seat heating command",
		ValueDescriptions: []string{
			"0: without_remote_control",
			"1: Remote_open_passenger_seat_heating_first_gear",
			"2: Remote_passenger_seat_heating_second_gear",
			"3: Remote_passenger_seat_heating_third_gear",
			"4: Remote_closing_passenger_seat_heating",
			"5: Reserved",
			"6: Reserved",
			"7: Reserved",
		},
		ReceiverNodes: []string{
			"GW",
		},
		DefaultValue: 0,
	}

	in := descriptor.Signal{
		Name:             "TBOX_RemPassSeatHeatgCmd",
		Start:            23,
		Length:           3,
		IsBigEndian:      true,
		IsSigned:         false,
		IsMultiplexer:    false,
		IsMultiplexed:    false,
		MultiplexerValue: 0,
		Offset:           0,
		Scale:            1,
		Min:              0,
		Max:              7,
		Unit:             "",
		Description:      "Remote passenger seat heating command",
		ValueDescriptions: []*descriptor.ValueDescription{
			{
				Value:       0,
				Description: "without_remote_control",
			},
			{
				Value:       1,
				Description: "Remote_open_passenger_seat_heating_first_gear",
			},
			{
				Value:       2,
				Description: "Remote_passenger_seat_heating_second_gear",
			},
			{
				Value:       3,
				Description: "Remote_passenger_seat_heating_third_gear",
			},
			{
				Value:       4,
				Description: "Remote_closing_passenger_seat_heating",
			},
			{
				Value:       5,
				Description: "Reserved",
			},
			{
				Value:       6,
				Description: "Reserved",
			},
			{
				Value:       7,
				Description: "Reserved",
			},
		},
		ReceiverNodes: []string{
			"GW",
		},
		DefaultValue: 0,
	}

	s := common.SignalDesc{}
	s.CopyFromCAN(&in)

	assert.Equal(t, expOut, s)
}

func TestCopyMessage(t *testing.T) {
	in := &descriptor.Message{
		Name:        "Diag_EPS2_Resp",
		ID:          2045,
		IsExtended:  false,
		SendType:    0,
		Length:      8,
		Description: "",
		SenderNode:  "GW",
		CycleTime:   1000000,
		DelayTime:   2000000,
	}

	expOut := common.MessageDesc{
		Name:        "Diag_EPS2_Resp",
		ID:          2045,
		IsExtended:  false,
		SendType:    "None",
		Length:      8,
		Description: "",
		SenderNode:  "GW",
		ECUName:     "EPS2",
		CycleTime:   1000000,
		DelayTime:   2000000,
	}

	s := common.MessageDesc{}
	s.CopyFromCAN(in)

	assert.Equal(t, expOut, s)
}
