from fastapi import FastAPI

PLUGIN_META = {
    "name": "cin7_import",
    "display_name": "Cin7 数据同步",
    "description": "从 Cin7 自动同步商品、分类、品牌和客户到本地系统。",
    "version": "1.0.0",
    "category": "库存 / ERP",
    "icon": "C",
    "has_config": True,
    "config_fields": [
        {"key": "api_username", "label": "Cin7 API Username", "type": "text", "required": True},
        {"key": "api_password", "label": "Cin7 API Password", "type": "password", "required": True},
        {"key": "base_url", "label": "API Base URL", "type": "text", "default": "https://api.cin7.com/api"},
        {"key": "sync_products", "label": "同步商品", "type": "boolean", "default": "true"},
        {"key": "sync_categories", "label": "同步分类", "type": "boolean", "default": "true"},
        {"key": "sync_brands", "label": "同步品牌", "type": "boolean", "default": "true"},
        {"key": "sync_contacts", "label": "同步客户", "type": "boolean", "default": "true"},
        {"key": "sync_price", "label": "同步价格", "type": "boolean", "default": "true"},
        {"key": "auto_delist_zero_stock", "label": "库存为0自动下架", "type": "boolean", "default": "true"},
        {"key": "sync_status", "label": "同步启用/禁用状态（分类和品牌）", "type": "boolean", "default": "true"},
        {"key": "products_interval_minutes", "label": "商品同步间隔（分钟）", "type": "number", "default": 30},
        {"key": "contacts_interval_minutes", "label": "客户同步间隔（分钟）", "type": "number", "default": 60},
        {"key": "level_mapping", "label": "价格列→会员等级映射（JSON）", "type": "textarea", "default": "{}"},
    ],
}


def init_plugin(app: FastAPI) -> None:
    from app.plugins.cin7_import.router import router
    from app.plugins.cin7_import.scheduler import register_scheduler

    app.include_router(router, prefix="/api/admin")
    register_scheduler(app)
