import json from bot.db.engine import get_db async def record_analysis( telegram_id: int, channel: str, depth: str, focus_areas: list[str], model_id: str, stars_paid: int = 0, report_path: str | None = None, ) -> int: db = await get_db() cursor = await db.execute( "INSERT INTO analyses (telegram_id, channel, depth, focus_areas, model_id, stars_paid, report_path) " "VALUES (?, ?, ?, ?, ?, ?, ?)", (telegram_id, channel, depth, json.dumps(focus_areas), model_id, stars_paid, report_path), ) await db.commit() return cursor.lastrowid async def update_report_path(analysis_id: int, report_path: str) -> None: db = await get_db() await db.execute( "UPDATE analyses SET report_path = ? WHERE id = ?", (report_path, analysis_id) ) await db.commit() async def record_payment( telegram_id: int, telegram_payment_id: str, stars_amount: int, analysis_id: int | None = None, ) -> int: db = await get_db() cursor = await db.execute( "INSERT INTO payments (telegram_id, telegram_payment_id, stars_amount, analysis_id) " "VALUES (?, ?, ?, ?)", (telegram_id, telegram_payment_id, stars_amount, analysis_id), ) await db.commit() return cursor.lastrowid