# -*- coding: utf-8 -*-
from __future__ import annotations

import uuid

from django.http import HttpHeaders, HttpRequest

from hotpocket_backend.apps.core.context import REQUEST_ID


class RequestIDMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request: HttpRequest) -> HttpHeaders:
        request_id = str(uuid.uuid4())

        REQUEST_ID.set(request_id)

        response = self.get_response(request)
        response["X-RequestID"] = REQUEST_ID.get()

        return response
