# coding=utf-8

from rest_framework import generics

from utils import response_ok, response_error
from utils.permission import IsCustomer, IsEmployee

from apps.rebate.models import PointLog, CashLog
from apps.rebate.filters import PointLogFilter, CashLogFilter
from apps.customer.rebate.serializers import PointLogSerializer, CashLogSerializer


class PointLogListView(generics.ListAPIView):
    permission_classes = [IsCustomer, ]
    queryset = PointLog.objects.filter()
    serializer_class = PointLogSerializer

    def filter_queryset(self, queryset):
        queryset = queryset.filter(customer=self.request.customer)
        f = PointLogFilter(self.request.GET, queryset=queryset)
        return f.qs


class CashLogListView(generics.ListAPIView):
    permission_classes = [IsCustomer, ]
    queryset = CashLog.objects.filter()
    serializer_class = CashLogSerializer

    def filter_queryset(self, queryset):
        queryset = queryset.filter(customer=self.request.customer)
        f = CashLogFilter(self.request.GET, queryset=queryset)
        return f.qs
