from sqlmodel import Session
from models import Notification

def create_notification(session: Session, user_id: int, title: str, message: str, type: str, link: str = None):
    notification = Notification(
        user_id=user_id,
        title=title,
        message=message,
        type=type,
        link=link
    )
    session.add(notification)
    # Note: caller is responsible for commit if part of larger transaction, 
    # but for simple notification triggers, we can commit here or let caller do it.
    # To be safe and atomic, usually we add to session and let caller commit.
    # But for a helper, instant commit ensures specific notification persistence.
    session.commit()
    session.refresh(notification)
    return notification
