
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession

from src.services.expense_item_service import ExpenseItemService
from src.db.models.app_user import AppUser
from src.api.v1.deps import require_admin
from src.db.session import get_db
from src.domain.schemas import (
    BaseSingleResponse,
    ExpenseItemResponseSchema,
)

router = APIRouter(prefix="/expense-item", tags=["expense-item"])


@router.get("/{item_id}", response_model=BaseSingleResponse[ExpenseItemResponseSchema])
async def get_expense_item_by_id(
    item_id: int,
    db: AsyncSession = Depends(get_db),
    current_user: AppUser = Depends(require_admin),
):
    """Получение записи expense item по ID."""
    service = ExpenseItemService(db)
    result = await service.get(item_id, user=current_user)
    if not result:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=f"Expense Item не найден",
        )
    return BaseSingleResponse(
        success=True,
        message="Запись Expense Item",
        result=ExpenseItemResponseSchema.model_validate(result),
    )
