from rest_framework import views, permissions, status
from rest_framework.response import Response
from .models import BrandingSetting
from .serializers import BrandingSettingSerializer

class BrandingView(views.APIView):
    def get_permissions(self):
        if self.request.method == 'GET':
            return [permissions.AllowAny()]
        return [permissions.IsAdminUser()]

    def get(self, request):
        setting = BrandingSetting.get_solo()
        return Response(BrandingSettingSerializer(setting).data)

    def post(self, request):
        setting = BrandingSetting.get_solo()
        serializer = BrandingSettingSerializer(setting, data=request.data, partial=True)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
