"""admin 钱包:金币流水 + 现金流水(跨用户,可按 user_id 过滤)。手动调金币见 M3。"""
from __future__ import annotations

from typing import Annotated

from fastapi import APIRouter, Depends, Query

from app.admin.deps import AdminDb, get_current_admin
from app.admin.repositories import queries
from app.admin.schemas.common import CursorPage
from app.admin.schemas.wallet import CashTxnOut, CoinTxnOut

router = APIRouter(
    prefix="/admin/api/wallet",
    tags=["admin-wallet"],
    dependencies=[Depends(get_current_admin)],
)


@router.get("/coin-transactions", response_model=CursorPage[CoinTxnOut], summary="金币流水")
def coin_transactions(
    db: AdminDb,
    user_id: Annotated[int | None, Query()] = None,
    biz_type: Annotated[str | None, Query()] = None,
    limit: Annotated[int, Query(ge=1, le=100)] = 20,
    cursor: Annotated[int | None, Query()] = None,
) -> CursorPage[CoinTxnOut]:
    items, next_cursor = queries.list_all_coin_transactions(
        db, user_id=user_id, biz_type=biz_type, limit=limit, cursor=cursor,
    )
    return CursorPage(
        items=[CoinTxnOut.model_validate(t) for t in items], next_cursor=next_cursor,
    )


@router.get("/cash-transactions", response_model=CursorPage[CashTxnOut], summary="现金流水")
def cash_transactions(
    db: AdminDb,
    user_id: Annotated[int | None, Query()] = None,
    biz_type: Annotated[str | None, Query()] = None,
    limit: Annotated[int, Query(ge=1, le=100)] = 20,
    cursor: Annotated[int | None, Query()] = None,
) -> CursorPage[CashTxnOut]:
    items, next_cursor = queries.list_all_cash_transactions(
        db, user_id=user_id, biz_type=biz_type, limit=limit, cursor=cursor,
    )
    return CursorPage(
        items=[CashTxnOut.model_validate(t) for t in items], next_cursor=next_cursor,
    )
