from typing import Annotated

from fastapi import Depends
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer

from shared import exceptions as e
from shared.redis import client as cache

BEARER = HTTPBearer()


async def login(
    credentials: Annotated[HTTPAuthorizationCredentials, Depends(BEARER)],
):
    is_exist = cache.get(credentials.credentials)

    if is_exist is None:
        raise e.UnauthorizedException

    return True
