import jingrow


def process_status_task(pg, method=None):

    # 检查文档是否有status和image_model字段
    meta = jingrow.get_meta(pg.pagetype)
    jingrow.db.commit()
    
    if not (meta.has_field("status")):
        return
    
    # 根据状态分配任务
    if pg.status == "待出图":
        # 根据绘画工具选择不同的处理方式
        if pg.image_model == "Jart":
            jingrow.enqueue(
                "jingrow.ai.api.jart.process_jart_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )
        elif pg.image_model == "Jart v1":
            jingrow.enqueue(
                "jingrow.ai.api.jart_v1.process_jart_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )
        elif pg.image_model == "Flux":
            jingrow.enqueue(
                "jingrow.ai.api.comfyui_flux.process_comfyui_flux_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )
        elif pg.image_model == "Midjourney":
            jingrow.enqueue(
                "jingrow.ai.api.midjourney.process_midjourney_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )
        elif pg.image_model == "Stable Diffusion":
            jingrow.enqueue(
                "jingrow.ai.api.comfyui_sd.process_comfyui_sd_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            ) 

    if pg.status == "待描述":
        jingrow.enqueue(
                "jingrow.ai.api.describe_image.process_describe_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )

    if pg.status == "待翻译":
        jingrow.enqueue(
            "jingrow.ai.api.translate.process_translate_task",
            pg_name=pg.name,
            pagetype=pg.pagetype
        )

    if pg.status == "待转换为矢量图":
        jingrow.enqueue(
                "jingrow.ai.api.jvector.process_jvector_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )

    if pg.status == "待放大图片":
        jingrow.enqueue(
                "jingrow.ai.api.jupscale.process_upscale_image_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )        

    if pg.status == "待去背景":
        jingrow.enqueue(
                "jingrow.ai.api.rmbg.process_remove_background_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )   

    if pg.status == "待添加背景颜色":
        jingrow.enqueue(
                "jingrow.ai.api.add_bg.process_add_background_task",
                pg_name=pg.name,
                pagetype=pg.pagetype
            )