from typing import Callable, Type

from fastapi import Depends

from src.db.database import Database
from src.depends.database import get_database
from src.services.base_service import BaseService


def get_service(Service_type: Type[BaseService]) -> Callable:
    def get_service(db: Database = Depends(get_database)) -> Type[BaseService]:
        repositories = {key: repository(db) for key, repository in Service_type.REPOSITORIES.items()}
        clients = {key: client() for key, client in Service_type.CLIENTS.items()}
        return Service_type(repositories=repositories, clients=clients)
    return get_service
