from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession from app.models.models import Notification, NotificationType, User async def create_notification( db: AsyncSession, user_id: int, title: str, message: str, notification_type: str = NotificationType.SYSTEM.value, related_debt_id: int | None = None, related_plan_id: int | None = None, ) -> Notification: n = Notification( user_id=user_id, title=title, message=message, type=notification_type, related_debt_id=related_debt_id, related_plan_id=related_plan_id, ) db.add(n) return n async def create_system_broadcast( db: AsyncSession, title: str, message: str, ) -> int: users = await db.execute(select(User).where(User.status == "active")) count = 0 for user in users.scalars().all(): db.add(Notification( user_id=user.id, title=title, message=message, type=NotificationType.SYSTEM.value, )) count += 1 await db.commit() return count