# Path: esteid/exceptions.py
# class CanceledByUser(InvalidParameters):
#     """User canceled the operation."""
# 
#     status = HTTPStatus.CONFLICT
# 
#     default_message = _("The signing operation was canceled by the user.")
# 
# class EsteidError(Exception):
#     """
#     A generic Esteid error.
# 
#     Provides an interface for displaying a translated message to the user.
# 
#     Note: by default, any message passed as a first positional argument is ignored, because it only
#     serves for better logging. The User Interface should display a verbose error message
#     in case of a user-caused error so that user can take action accordingly. Errors caused by service malfunction
#     are likely not informative to a user without malicious intent.
# 
#     If the default message contains {key} placeholders, the exception is supposed to be
#     raised with kwargs, these will be passed on to <translated default message>.format(**kwargs).
#     """
# 
#     status = HTTPStatus.INTERNAL_SERVER_ERROR
# 
#     default_message = _("Something went wrong")
# 
#     kwargs: dict
# 
#     def __init__(self, message=None, **kwargs):
#         super().__init__(message)
#         self.kwargs = kwargs
# 
#     def get_message(self):
#         return str(self.default_message).format(**self.kwargs)
# 
#     def get_user_error(self):
#         return {
#             "error": self.__class__.__name__,  # error code that can be bound to JS translations
#             # TODO review errors and add translations
#             "message": self.get_message(),
#         }
# 
# class InvalidParameters(EsteidError):
#     """Invalid initialization parameters received from the request."""
# 
#     status = HTTPStatus.BAD_REQUEST
# 
#     default_message = _("Invalid parameters.")


import json
import logging
from http import HTTPStatus
from typing import Callable, TYPE_CHECKING
from django.core.exceptions import ValidationError as DjangoValidationError
from django.http import Http404, HttpRequest, JsonResponse, QueryDict
from django.utils.translation import gettext
from esteid.exceptions import CanceledByUser, EsteidError, InvalidParameters
    from rest_framework.exceptions import ValidationError as DRFValidationError
    from django.contrib.sessions import base_session
    class DRFValidationError:
        pass


if TYPE_CHECKING:
    # Make type checkers aware of request.session attribute which is missing on the HttpRequest class

    class RequestType(HttpRequest):
        session: base_session.AbstractBaseSession
        data: dict


logger = logging.getLogger(__name__)


class SessionViewMixin:
    """
    Provides POST and PATCH method handlers for auth/signing session management.

    Also does common error handling.
    """

    class Status:
        ERROR = "error"
        PENDING = "pending"
        SUCCESS = "success"

    start_session: Callable
    finish_session: Callable


# Path: esteid/exceptions.py
# class CanceledByUser(InvalidParameters):
#     """User canceled the operation."""
# 
#     status = HTTPStatus.CONFLICT
# 
#     default_message = _("The signing operation was canceled by the user.")
# 
# class EsteidError(Exception):
#     """
#     A generic Esteid error.
# 
#     Provides an interface for displaying a translated message to the user.
# 
#     Note: by default, any message passed as a first positional argument is ignored, because it only
#     serves for better logging. The User Interface should display a verbose error message
#     in case of a user-caused error so that user can take action accordingly. Errors caused by service malfunction
#     are likely not informative to a user without malicious intent.
# 
#     If the default message contains {key} placeholders, the exception is supposed to be
#     raised with kwargs, these will be passed on to <translated default message>.format(**kwargs).
#     """
# 
#     status = HTTPStatus.INTERNAL_SERVER_ERROR
# 
#     default_message = _("Something went wrong")
# 
#     kwargs: dict
# 
#     def __init__(self, message=None, **kwargs):
#         super().__init__(message)
#         self.kwargs = kwargs
# 
#     def get_message(self):
#         return str(self.default_message).format(**self.kwargs)
# 
#     def get_user_error(self):
#         return {
#             "error": self.__class__.__name__,  # error code that can be bound to JS translations
#             # TODO review errors and add translations
#             "message": self.get_message(),
#         }
# 
# class InvalidParameters(EsteidError):
#     """Invalid initialization parameters received from the request."""
# 
#     status = HTTPStatus.BAD_REQUEST
# 
#     default_message = _("Invalid parameters.")


# Path: esteid/mixins.py
import json
import logging
from http import HTTPStatus
from typing import Callable, TYPE_CHECKING
from django.core.exceptions import ValidationError as DjangoValidationError
from django.http import Http404, HttpRequest, JsonResponse, QueryDict
from django.utils.translation import gettext
from esteid.exceptions import CanceledByUser, EsteidError, InvalidParameters
    from rest_framework.exceptions import ValidationError as DRFValidationError
    from django.contrib.sessions import base_session

    class DRFValidationError:
        pass


if TYPE_CHECKING:
    # Make type checkers aware of request.session attribute which is missing on the HttpRequest class

    class RequestType(HttpRequest):
        session: base_session.AbstractBaseSession
        data: dict


logger = logging.getLogger(__name__)


class SessionViewMixin:
    """
    Provides POST and PATCH method handlers for auth/signing session management.

    Also does common error handling.
    """

    class Status:
        ERROR = "error"
        PENDING = "pending"
        SUCCESS = "success"

    start_session: Callable
    finish_session: Callable


    def report_error(self, e: EsteidError):