package order

import (
	"context"
)

// ListPendingRefund 查询所有待客服审核退款的订单。
func (r *Repository) ListPendingRefund(ctx context.Context) ([]OrderDTO, error) {
	var rows []orderRow
	err := r.adminQuery(ctx).
		Where("o.refund_status = ?", refundStatusPendingReview).
		Order("o.updated_at ASC, o.id ASC").
		Limit(200).
		Scan(&rows).Error
	if err != nil {
		return nil, err
	}

	db := r.db.WithContext(ctx)
	paymentTimeoutMinutes := pendingPaymentTimeoutMinutes(db)
	items := make([]OrderDTO, 0, len(rows))
	for _, row := range rows {
		dto := row.toAdminDTO()
		applyPaymentDeadline(&dto, row.RentalOrder, paymentTimeoutMinutes)
		items = append(items, dto)
	}
	return items, nil
}
