from sqladmin import Admin, ModelView
from src.models.entities import ProjectDB, AssetDB, EpisodeDB, StoryboardDB

class ProjectAdmin(ModelView, model=ProjectDB):
    column_list = [ProjectDB.id, ProjectDB.name, ProjectDB.type, ProjectDB.status, ProjectDB.created_at]
    column_searchable_list = [ProjectDB.name, ProjectDB.id]
    column_sortable_list = [ProjectDB.created_at]
    icon = "fa-solid fa-diagram-project"

class AssetAdmin(ModelView, model=AssetDB):
    column_list = [AssetDB.id, AssetDB.name, AssetDB.type, AssetDB.project_id]
    column_searchable_list = [AssetDB.name, AssetDB.id, AssetDB.type]
    # 列_filters = ["type", "project_id"]
    # 列_filters = [AssetDB.type, AssetDB.project_id]
    icon = "fa-solid fa-cube"

class EpisodeAdmin(ModelView, model=EpisodeDB):
    column_list = [EpisodeDB.id, EpisodeDB.title, EpisodeDB.order_index, EpisodeDB.status, EpisodeDB.project_id]
    column_searchable_list = [EpisodeDB.title, EpisodeDB.id]
    # 列_filters = [EpisodeDB.status, EpisodeDB.project_id]
    icon = "fa-solid fa-film"

class StoryboardAdmin(ModelView, model=StoryboardDB):
    column_list = [StoryboardDB.id, StoryboardDB.project_id, StoryboardDB.episode_id, StoryboardDB.order_index]
    # 列_filters = [StoryboardDB.project_id, StoryboardDB.episode_id]
    icon = "fa-solid fa-image"

def setup_admin(app, engine):
    admin = Admin(app, engine, title="Pixel管理后台")
    admin.add_view(ProjectAdmin)
    admin.add_view(AssetAdmin)
    admin.add_view(EpisodeAdmin)
    admin.add_view(StoryboardAdmin)
