from django.http import JsonResponse
from django.utils import timezone
from django.views import View


class ServerTimeView(View):
    """
    GET /api/v1/time/
    Returns server UTC time for countdown sync.
    The client computes offset (serverTime - clientTime) and applies it
    to all subsequent countdown ticks. Re-synced every 20 seconds.
    """

    def get(self, request):
        now = timezone.now()
        return JsonResponse({
            'server_time': now.isoformat(),
            'timestamp': int(now.timestamp() * 1000),
        })
