"""微信登录插件

支持三种登录方式（均作为 /store/auth/wechat 路由挂载）：
  1. 小程序登录（POST /miniapp）
  2. 公众号 OAuth（GET /mp  -> GET /mp/callback）
  3. 开放平台扫码（GET /open -> GET /open/callback）

Admin 配置接口（/admin/wechat-auth）：
  GET  /config  获取微信应用配置
  PUT  /config  更新微信应用配置
"""
from fastapi import FastAPI
from app.plugins.wechat_auth.router import router as store_router
from app.plugins.wechat_auth.admin_router import router as admin_router

PLUGIN_META = {
    "name":         "wechat_auth",
    "display_name": "微信登录",
    "description":  "支持小程序登录、公众号 H5 登录、开放平台扫码登录，自动绑定/创建客户账户。",
    "icon":         "💬",
    "category":     "社交登录",
    "version":      "1.0.0",
    "author":       "LS",
    "config_fields": [
        {"key": "miniapp_appid",    "label": "小程序 AppID",          "type": "text",     "secret": False},
        {"key": "miniapp_secret",   "label": "小程序 AppSecret",      "type": "password", "secret": True},
        {"key": "mp_appid",         "label": "公众号 AppID",          "type": "text",     "secret": False},
        {"key": "mp_secret",        "label": "公众号 AppSecret",      "type": "password", "secret": True},
        {"key": "open_appid",       "label": "开放平台 AppID",        "type": "text",     "secret": False},
        {"key": "open_secret",      "label": "开放平台 AppSecret",    "type": "password", "secret": True},
        {"key": "wxpay_mch_id",     "label": "微信支付商户号",        "type": "text",     "secret": False},
        {"key": "wxpay_api_v3_key", "label": "APIv3 密钥（32字节）", "type": "password", "secret": True},
        {"key": "wxpay_serial_no",  "label": "证书序列号",            "type": "text",     "secret": False},
        {"key": "wxpay_private_key","label": "商户私钥 PEM",          "type": "textarea", "secret": True},
        {"key": "wxpay_notify_url",     "label": "支付回调地址（HTTPS）",    "type": "text",     "secret": False},
        {"key": "wxpay_platform_cert",  "label": "微信平台公钥 PEM（验签用）","type": "textarea", "secret": False},
    ],
}


def init_plugin(app: FastAPI) -> None:
    app.include_router(store_router, prefix="/api")
    app.include_router(admin_router, prefix="/api")
