from __future__ import annotations

import typing as t

import strawberry
from sqlmodel import Field, Relationship, SQLModel

from .schema_generation import create_array_relationship_resolver, create_query_root


class AddressModel(SQLModel, table=True):
    __tablename__ = "addresses"
    id: t.Optional[int] = Field(
        default=None, primary_key=True, index=True, nullable=False
    )
    street: str
    state: str
    country: str
    zip: str
    users: t.List["UserModel"] = Relationship(back_populates="address")


class UserModel(SQLModel, table=True):
    __tablename__ = "users"
    id: t.Optional[int] = Field(
        default=None, primary_key=True, index=True, nullable=False
    )
    age: int
    password: t.Optional[str]
    address_id: t.Optional[int] = Field(default=None, foreign_key="addresses.id")
    address: t.Optional[AddressModel] = 