package commerce

import (
	"testing"
	"time"
)

func TestBalanceLogItemMapUsesAPIFieldNames(t *testing.T) {
	refNo := "ORDER-1001"
	remark := "order payment"
	createdAt := time.Date(2026, time.March, 12, 8, 30, 0, 0, time.UTC)

	operatorID := int64(33)
	item := balanceLogItemMap(BalanceLog{
		ID:           11,
		UserID:       22,
		ChangeType:   "order_pay",
		Delta:        -3500,
		BalanceAfter: 6500,
		RefNo:        &refNo,
		OperatorID:   &operatorID,
		Remark:       &remark,
		CreatedAt:    createdAt,
	})

	checks := map[string]any{
		"id":            int64(11),
		"user_id":       int64(22),
		"change_type":   "order_pay",
		"delta":         -3500,
		"balance_after": 6500,
		"created_at":    createdAt,
	}
	for key, want := range checks {
		if got := item[key]; got != want {
			t.Fatalf("%s = %#v, want %#v", key, got, want)
		}
	}
	if got := item["ref_no"]; got != &refNo {
		t.Fatalf("ref_no = %#v, want pointer to %q", got, refNo)
	}
	if got := item["remark"]; got != &remark {
		t.Fatalf("remark = %#v, want pointer to %q", got, remark)
	}
	if got := item["operator_id"]; got != &operatorID {
		t.Fatalf("operator_id = %#v, want pointer to %d", got, operatorID)
	}

	for _, legacyKey := range []string{"ID", "UserID", "ChangeType", "Delta", "BalanceAfter", "RefNo", "OperatorID", "Remark", "CreatedAt"} {
		if _, exists := item[legacyKey]; exists {
			t.Fatalf("legacy field %q must not be exposed", legacyKey)
		}
	}
}
