from __future__ import annotations

from uuid import UUID

from fastapi import HTTPException

from core.auth.models import CurrentUser


class BaseService:
    _current_user: CurrentUser | None

    def __init__(self, current_user: CurrentUser | None) -> None:
        self._current_user = current_user

    def require_current_user(self) -> CurrentUser:
        if self._current_user is None:
            raise HTTPException(status_code=401, detail="Unauthorized")
        return self._current_user

    def require_user_id(self) -> UUID:
        return self.require_current_user().id
