"""
配置路由：CONFIG-1 技能类型。

前缀 /api/xcx/config，由 main.py 注册。
"""

from __future__ import annotations

import logging

from fastapi import APIRouter, Depends

from app.auth.dependencies import CurrentUser
from app.middleware.permission import require_approved
from app.schemas.xcx_config import SkillTypeItem
from app.services import fdw_queries
from app.trace.decorators import trace_service

logger = logging.getLogger(__name__)

router = APIRouter(prefix="/api/xcx/config", tags=["xcx-config"])


@router.get("/skill-types", response_model=list[SkillTypeItem])
@trace_service("获取技能类型配置", "Get skill types config")
async def get_skill_types(
    user: CurrentUser = Depends(require_approved()),
):
    """技能类型配置（CONFIG-1）。查询失败降级返回空数组。"""
    try:
        from app.database import get_connection
        conn = get_connection()
        try:
            return fdw_queries.get_skill_types(conn, user.site_id)
        finally:
            conn.close()
    except Exception:
        logger.warning("CONFIG-1 技能类型查询失败，降级为空数组", exc_info=True)
        return []
