# (c) cavaliba.com - data - admin.py

from django.contrib import admin

from app_data.models import DataClass
from app_data.models import DataSchema
from app_data.models import DataInstance
from app_data.models import DataRegistry
from app_data.models import DataEAV
from app_data.models import DataFile
from app_data.models import DataRevision
from app_data.models import DataTask

@admin.register(DataClass)
class DataClassAdmin(admin.ModelAdmin):
    list_display = ('keyname', 'displayname', 'is_bigset', 'order', 'page', 'p_read', 'id')
    ordering = ["keyname"]
    list_filter = ["page"]

@admin.register(DataSchema)
class DataSchemaAdmin(admin.ModelAdmin):
    list_display = ('classname', 'keyname', 'displayname', 'dataformat', 'dataformat_ext', 'default_value', 
        'cardinal_min', 'cardinal_max', 'page', 'order', 'id')
    ordering = ["classname", "order", "keyname"]
    list_filter = ["classname","dataformat"]


@admin.register(DataInstance)
class DataInstanceAdmin(admin.ModelAdmin):
    list_display = ('classname', 'keyname', 'displayname', 'is_enabled', 'p_read', 'last_update', 'id')
    #ordering=["classname","keyname"]
    ordering = ["-last_update"]
    list_filter = ["classname"]


# DataRegistry
@admin.register(DataRegistry)
class DataRegistryAdmin(admin.ModelAdmin):
   list_display = ('key', 'value', 'id')

# DataEAV
@admin.register(DataEAV)
class DataEAVAdmin(admin.ModelAdmin):
    list_display = ('iid','classname', 'keyname', 'displayname', 'fieldname', 'format', 'value' , 'last_update','id')
    ordering = ["id"]
    list_filter = ["classname","format","fieldname"]

# DataFile
@admin.register(DataFile)
class DataFileAdmin(admin.ModelAdmin):
    list_display = ('fileid', 'filename', 'filepath', 'displayname', 'size', 'is_enabled', 'last_update','id')
    ordering = ["-id"]
    #list_filter = ["is_enabled", "is_encrypted"]

# DataRevision 3.23
@admin.register(DataRevision)
class DataRevisionAdmin(admin.ModelAdmin):
    list_display = ('date', 'classname', 'keyname', 'username', 'action','id')
    ordering = ["-id"]
    #list_filter = ["is_enabled", "is_encrypted"]   

# DataTask 3.33
@admin.register(DataTask)
class DataTaskAdmin(admin.ModelAdmin):
    list_display = ('created_at', 'name', 'owner_type', 'owner_id', 'state', 'id')
    ordering = ["-id"]
    list_filter = ["state", "owner_type"]

#  handle      = models.UUIDField(default=uuid.uuid4, unique=True, db_index=True)
#  owner_type  = models.CharField(max_length=16, choices=DATATASK_OWNER_TYPE_CHOICES, default="user")
#  owner_id    = models.CharField(max_length=128, db_index=True)
#  name        = models.CharField(max_length=256)
#  singleton   = models.CharField(max_length=64, blank=True, null=True, db_index=True)
#  state       = models.CharField(max_length=16, choices=DATATASK_STATE_CHOICES, default="QUEUED", db_index=True)
#  params      = models.JSONField(blank=True, null=True)
#  progress    = models.JSONField(blank=True, null=True)
#  output      = models.JSONField(blank=True, null=True)
#  attachment  = models.JSONField(blank=True, null=True)
#  created_at  = models.DateTimeField(auto_now_add=True, db_index=True)
#  finished_at = models.DateTimeField(blank=True, null=True)
