import asyncio
import uuid
from typing import List, Optional

import pytest
from fastapi_users import models
from pydantic import UUID4
from sqlmodel import Field, Relationship

from fastapi_users_db_sqlmodel import SQLModelBaseOAuthAccount, SQLModelBaseUserDB


class User(models.BaseUser):
    first_name: Optional[str]


class UserCreate(models.BaseUserCreate):
    first_name: Optional[str]


class UserUpdate(models.BaseUserUpdate):
    pass


class UserDB(SQLModelBaseUserDB, User, table=True):
    class Config:
        orm_mode = True


class UserOAuth(User):
    pass


class UserDBOAuth(SQLModelBaseUserDB, table=True):
    __tablename__ = "user_oauth"
    oauth_accounts: List["OAuthAccount"] = Relationship(
        back_populates="user",
        sa_relationship_kwargs={"lazy": "joined", "cascade": "all, delete"},
    )


class OAuthAccount(SQLModelBaseOAuthAccount, table=True):
    user_id: UUID4 = 