package service

import (
	"testing"

	repository "gitlab.com/mbugroup/lti-api.git/internal/modules/closings/repositories"
)

func TestBuildSapronakDetailsMapsAdjustmentOutgoingAsUsage(t *testing.T) {
	res := buildSapronakDetails(
		map[uint][]repository.SapronakDetailRow{},
		map[uint][]repository.SapronakDetailRow{},
		map[uint][]repository.SapronakDetailRow{},
		map[uint][]repository.SapronakDetailRow{
			17: {
				{
					ProductID:   17,
					ProductName: "PAKAN GROWING CRUMBLE 8603 MALINDO",
					Flag:        "PAKAN",
					QtyOut:      9000,
					Price:       6450,
				},
			},
		},
		map[uint][]repository.SapronakDetailRow{},
		map[uint][]repository.SapronakDetailRow{},
		map[uint][]repository.SapronakDetailRow{},
	)

	rows := res.AdjOutgoing[17]
	if len(rows) != 1 {
		t.Fatalf("expected 1 adjustment outgoing row, got %d", len(rows))
	}

	row := rows[0]
	if row.JenisTransaksi != "Pemakaian" {
		t.Fatalf("expected jenis_transaksi Pemakaian, got %q", row.JenisTransaksi)
	}
	if row.QtyKeluar != 9000 {
		t.Fatalf("expected qty_keluar 9000, got %.3f", row.QtyKeluar)
	}
	if row.Nilai != 58050000 {
		t.Fatalf("expected nilai 58050000, got %.3f", row.Nilai)
	}
}
