"""
Author: Michel Peltriaux
Created on: 14.12.25

"""
from abc import ABC

from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpRequest, JsonResponse
from django.utils.decorators import method_decorator
from django.views import View

from konova.decorators import default_group_required
from konova.utils.generators import IdentifierGenerator


class AbstractIdentifierGeneratorView(LoginRequiredMixin, View, ABC):
    _MODEL = None

    @method_decorator(default_group_required)
    def get(self, request: HttpRequest, *args, **kwargs):
        generator = IdentifierGenerator(model=self._MODEL)
        identifier = generator.generate_id()
        return JsonResponse(
            data={
                "gen_data": identifier
            }
        )