package validator_test

import (
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/testhelper"
	"github.com/fiskerinc/cloud-services/pkg/validator"
)

type TestECU struct {
	Name     string `validate:"ecu"`
	Expected string
}

var ecuValidTests = []TestECU{
	{Name: "BCM"},
	{Name: "TBOX"},
	{Name: "iBooster"},
}

func TestValidateECU(t *testing.T) {
	var tests = []TestECU{
		{
			Name:     "",
			Expected: "Key: 'TestECU.Name' Error:Field validation for 'Name' failed on the 'ecu' tag",
		},
		{
			Name:     "-",
			Expected: "Key: 'TestECU.Name' Error:Field validation for 'Name' failed on the 'ecu' tag",
		},
		{
			Name:     "-123",
			Expected: "Key: 'TestECU.Name' Error:Field validation for 'Name' failed on the 'ecu' tag",
		},
		{
			Name:     "abc",
			Expected: "Key: 'TestECU.Name' Error:Field validation for 'Name' failed on the 'ecu' tag",
		},
		{
			Name:     "ab12",
			Expected: "Key: 'TestECU.Name' Error:Field validation for 'Name' failed on the 'ecu' tag",
		},
	}

	tests = append(tests, ecuValidTests...)

	for _, test := range tests {
		err := validator.ValidateStruct(test)
		if err == nil && test.Expected != "" {
			t.Errorf(testhelper.TestErrorTemplate, test.Name, test.Expected, err)
		} else if err != nil && err.Error() != test.Expected {
			t.Errorf(testhelper.TestErrorTemplate, test.Name, test.Expected, err.Error())
		}
	}
}
