from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status, permissions

from apps.payments.models import PaymentTransaction


class AdminPaymentListView(APIView):
    permission_classes = [permissions.IsAdminUser]

    def get(self, request):
        # return a lightweight list of transactions
        qs = PaymentTransaction.objects.all().order_by('-created_at')[:100]
        txns = [
            {
                'id': str(t.id),
                'provider': t.provider,
                'amount': str(t.amount),
                'currency': t.currency,
                'status': t.status,
                'created_at': t.created_at.isoformat(),
            }
            for t in qs
        ]
        return Response({'transactions': txns}, status=status.HTTP_200_OK)
