from rest_framework.views import APIView
from rest_framework.response import Response
from django.shortcuts import get_object_or_404
from api.property_api.property.models import Property
from users.permission.sub_admin import IsCountryAdmin

class ApprovePropertyView(APIView):
    permission_classes = [IsCountryAdmin]

    def post(self, request, property_id):
        property = get_object_or_404(Property, id=property_id)

        if property.country != request.user.country:
            return Response({"error": "Not allowed"}, status=403)

        property.is_approved = True
        property.save()

        return Response({"message": "Property approved"})
