from rest_framework import viewsets, filters
from rest_framework.decorators import action, schema, api_view
from rest_framework.parsers import MultiPartParser
from rest_framework.generics import ListAPIView
from django.http import JsonResponse, HttpResponse
from django_filters.rest_framework import DjangoFilterBackend

from .. import models, serializers
from ..schemas import ParaderoImageSchema
from PIL import Image
import io
import coreapi
import logging

class ParaderoViewSet(viewsets.ModelViewSet):
    queryset = models.Paradero.objects.all()
    serializer_class = serializers.ParaderoSerializer

# class ParaderoImagenListView(ListAPIView):
#     queryset = models.ParaderoImagen.objects.all()
#     serializer_class = serializers.ParaderoImagenSerializer
#     filter_backends = [filters.SearchFilter]
#     search_fields = ['id_paradero']




"""
    def retrieve(self, request, pk):
        data = models.ParaderoImagen.objects.filter(id_paradero_imagen = pk).first()
        response = HttpResponse(content_type=data.content_type)
        response['Content-Disposition'] = 'inline'
        response.write(data.imagen)
        return response

    def create(self, request, pk = None):
        imagen = request.FILES['imagen']
        id_paradero = request.data.get('id_paradero')
        content_type = imagen.content_type
        imagen_bytea = imagen.read()

        paradero = models.Paradero.objects.filter(id_paradero = id_paradero).first()

        paradero_imagen = models.ParaderoImagen(
            id_paradero = paradero,
            imagen = imagen_bytea,
            content_type = content_type
        )
        paradero_imagen.save()
        return JsonResponse({ 'ok': True })
"""