from app.repositories.base_repo import BaseRepo
from fastapi import HTTPException
from datetime import datetime, timezone

from app.common.models import Advisor, Notifications, CallsLog
from app.retell_service.services.retell_service import create_offline_message
from app.utils.exceptions import AuthorizationException, NotFoundException, UnauthorizedException

class NotificationsRepo(BaseRepo):    
    def __init__(self, db):
        super().__init__(db)

    def read_single_notification(self, notification_id: int) -> dict:
        """
        Read a single notification
        """
        notification = self.get_by_id(Notifications, notification_id)
        if not notification:
            raise NotFoundException(class_name="Notification", entity_id=notification_id)
        # if not self.current_user:
        #     raise UnauthorizedException()
        # if notification.user_id != self.current_user.id:
        #     raise AuthorizationException()
        notification.is_read = True
        notification.read_at = datetime.now(timezone.utc)
        self.db.commit()
        self.db.refresh(notification)
        return notification
    
