from typing import Callable, Type

from fastapi import Depends
from starlette.requests import Request

from src.db.database import Database
from src.repositories.base_repository import BaseRepository


def get_database(request: Request) -> Database:
    return request.app.state._db


def get_repository(Repo_type: Type[BaseRepository]) -> Callable:
    def get_repo(db: Database = Depends(get_database)) -> Type[BaseRepository]:
        return Repo_type(db)
    return get_repo
