from rest_framework import viewsets

from back_latienda.permissions import ReadOnly

from . import models
from . import serializers


class CountryViewSet(viewsets.ModelViewSet):
    model = models.Country
    serializer_class = serializers.CountrySerializer
    model_name = 'country'
    queryset = models.Country.objects.all()
    filterset_fields = ('name', )
    permission_classes = [ReadOnly]


class RegionViewSet(viewsets.ModelViewSet):
    model = models.Region
    serializer_class = serializers.RegionSerializer
    model_name = 'region'
    queryset = models.Region.objects.all()
    filterset_fields = ('name', 'country__name')
    permission_classes = [ReadOnly]


class ProvinceViewSet(viewsets.ModelViewSet):
    model = models.Province
    serializer_class = serializers.ProvinceSerializer
    model_name = 'region'
    queryset = models.Province.objects.all()
    filterset_fields = ('name', 'region__country__name')
    permission_classes = [ReadOnly]


class CityViewSet(viewsets.ModelViewSet):
    model = models.City
    serializer_class = serializers.CitySerializer
    model_name = 'city'
    queryset = models.City.objects.all()
    permission_classes = [ReadOnly]
    filterset_fields = ('name', 'province__name', 'province__region__name')
