package inspur

import (
	"testing"

	"git.mchus.pro/mchus/logpile/internal/models"
)

func TestExtractBoardInfo_PreservesBuiltinSerial(t *testing.T) {
	hw := &models.HardwareConfig{}
	fruList := []models.FRUInfo{
		{
			Description:  "Builtin FRU Device (ID 0)",
			SerialNumber: "21D634101",
		},
		{
			Description:  "SCM_FRU (ID 8)",
			SerialNumber: "CAR509K10613C10",
			ProductName:  "CA",
			Manufacturer: "inagile",
			PartNumber:   "YZCA-02758-105",
		},
	}

	extractBoardInfo(fruList, hw)

	if hw.BoardInfo.SerialNumber != "21D634101" {
		t.Fatalf("expected board serial 21D634101, got %q", hw.BoardInfo.SerialNumber)
	}
	if hw.BoardInfo.ProductName != "CA" {
		t.Fatalf("expected product name CA, got %q", hw.BoardInfo.ProductName)
	}
}

func TestExtractBoardInfo_DoesNotUsePSUVendorAsBoardManufacturer(t *testing.T) {
	hw := &models.HardwareConfig{}
	fruList := []models.FRUInfo{
		{
			Description:  "Builtin FRU Device (ID 0)",
			SerialNumber: "2KD605238",
		},
		{
			Description:  "PSU0_FRU (ID 30)",
			SerialNumber: "PMR315HS10F1A",
			ProductName:  "AP-CR3000F12BY",
			Manufacturer: "APLUSPOWER",
			PartNumber:   "18XA1M43400C2",
		},
	}

	extractBoardInfo(fruList, hw)

	if hw.BoardInfo.SerialNumber != "2KD605238" {
		t.Fatalf("expected board serial 2KD605238, got %q", hw.BoardInfo.SerialNumber)
	}
	if hw.BoardInfo.Manufacturer != "" {
		t.Fatalf("expected empty board manufacturer, got %q", hw.BoardInfo.Manufacturer)
	}
}
