from django.db import models
from enum import Enum

from BasicData.models import Historique, User


class Actions(Enum):
    """
    Enum for actions that can be performed on the data.
    """

    ADD = "add"
    EDIT = "edit"
    DELETE = "delete"
    LIST = "list"
    VIEW = "view"
    EXPORT = "export"
    IMPORT = "import"
    SEARCH = "search"
    FILTER = "filter"
    LOGIN = "login"
    LOGOUT = "logout"
    CHANGE_PASSWORD = "change_password"
    RESET_PASSWORD = "reset_password"
    CHANGE_USERNAME = "change_username"
    RESET_USERNAME = "reset_username"
    


class HistoriqueController:
    """
    Controller for historique.

    """
    
    def __init__(self, model, action: Actions, user: User):
        self.historique = Historique(
                user=user, 
                action=action.value, 
                model=f"{model.__class__.__name__} {model.id} {model}"
            )
        

    def get_historique(self):
        """
        Returns the historique.
        """
        return self.historique
    
    def add_historique(self, historique):
        """
        Adds a historique.
        """
        self.historique = historique

    
    def save_historique(self):
        """
        Saves the historique.
        """
        self.historique.save()