from .models import *


#TODO: TRACK USER LOGIN
def track_login(user_email):
    Edition.objects.create(
        user = user_email,
        types ='login',
    )
    return ''

#TODO: TRACK USER INSERT
def track_insert(user_email,obj,comment):
    obj_model_list = [ob.__class__.__name__ for ob in obj]
    obj_id_list = [ob.id for ob in obj]
    obj_instance_list = [ob for ob in obj]

    Edition.objects.create(
        user=user_email,
        types='insert',
        obj_model=obj_model_list,
        obj_id=obj_id_list,
        obj_instance=obj_instance_list,
        comment=comment,
    )
    return ''


#TODO: TRACK USER EDIT
def track_edit(user_email,obj,comment):
    obj_model_list = [ob.__class__.__name__ for ob in obj]
    obj_id_list = [ob.id for ob in obj]
    obj_instance_list = [ob for ob in obj]

    Edition.objects.create(
        user=user_email,
        types='edit',
        obj_model=obj_model_list,
        obj_id=obj_id_list,
        obj_instance=obj_instance_list,
        comment=comment,
    )
    return ''


#TODO: TRACK USER EDIT
def track_delete(user_email,obj,comment):
    obj_model_list = [ob.__class__.__name__ for ob in obj]
    obj_id_list = [ob.id for ob in obj]
    obj_instance_list = [ob for ob in obj]

    Edition.objects.create(
        user=user_email,
        types='delete',
        obj_model=obj_model_list,
        obj_id=obj_id_list,
        obj_instance=obj_instance_list,
        comment=comment,
    )
    return ''
