from typing import Callable

from sqlmodel import select, Session

from . import BaseRepository, engine
from ..models import ProfileDB, UserDB
from app.shared.exc import (
    EmailAlreadyTakenError,
    UserDoesNotExist,
    UsernameAlreadyTakenError)


class UserRepository(BaseRepository):
    model = UserDB

    @classmethod
    def create_with_profile(cls, **kwargs) -> UserDB:
        user = cls.model(**kwargs)
        user.profile = ProfileDB()
        user.profile.create_gravatar()
        user.save()
        return user

    @classmethod
    def get_all_ilike_username(cls,
                               search_for: str
                               ) -> list[UserDB]:
        with Session(engine) as session:
            return session.exec(