package mysql

import (
	"strings"
	"testing"

	"hyapp/services/wallet-service/internal/domain/ledger"
)

func TestRechargeBillsWhereUsesExclusiveEndMs(t *testing.T) {
	where, args := rechargeBillsWhereSQL(ledger.ListRechargeBillsQuery{
		AppCode:   "lalu",
		StartAtMS: 1778284800000,
		EndAtMS:   1778371200000,
	})
	if !strings.Contains(where, "rr.created_at_ms >= ?") || !strings.Contains(where, "rr.created_at_ms < ?") {
		t.Fatalf("recharge bill range must use [start_ms, end_ms): where=%s", where)
	}
	if len(args) != 4 || args[2] != int64(1778284800000) || args[3] != int64(1778371200000) {
		t.Fatalf("range args mismatch: %#v", args)
	}
}

func TestRechargeBillsWhereExcludesCoinSellerTransfers(t *testing.T) {
	where, args := rechargeBillsWhereSQL(ledger.ListRechargeBillsQuery{AppCode: "lalu"})
	if !strings.Contains(where, "wt.biz_type <> ?") {
		t.Fatalf("finance recharge bills must exclude coin seller user transfers: where=%s", where)
	}
	if len(args) < 2 || args[1] != bizTypeCoinSellerTransfer {
		t.Fatalf("coin seller transfer exclusion arg mismatch: %#v", args)
	}
}
