from rest_framework.views import APIView
from rest_framework.response import Response
from apps.core.utils import error_response
from rest_framework.permissions import IsAuthenticated
from apps.business.wallet.services.earnings_service import get_earnings_summary

class EarningsSummaryAPIView(APIView):
    permission_classes = [IsAuthenticated]

    def get(self, request):
        try:
            summary = get_earnings_summary(request.user)
        except Exception as e:
            return error_response(
                message=str(e),
                code="EARNINGS_SUMMARY_FAILED",
                status_code=400
            )
        return Response({
            "success": True,
            "data": summary
        })
