from datetime import datetime
from sqlmodel import Field, SQLModel, Relationship, Column, DateTime
from app.models.links import LinkGroupUser
from typing import List, Optional
from pydantic import EmailStr
from app.models.base_uuid_model import BaseUUIDModel
from uuid import UUID

class UserBase(SQLModel):
    first_name: str
    last_name: str
    email: EmailStr = Field(nullable=True, index=True, sa_column_kwargs={"unique": True})    
    is_active: bool = Field(default=True)
    is_superuser: bool = Field(default=False)
    birthdate: Optional[datetime] = Field(sa_column=Column(DateTime(timezone=True), nullable=True)) #birthday with timezone
    phone: Optional[str]
    state: Optional[str]
    country: Optional[str]
    address: Optional[str]    

class User(BaseUUIDModel, UserBase, table=True):    
    hashed_password: str = Field(
        nullable=False, index=True
    )
    role_id: Optional[UUID] = Field(default=None, foreign_key="role.id")
    role: Optional["Role"] = Relationship(back_populates="users", sa_relationship_kwargs={"lazy": "selectin"})
    groups: List["Group"] = Relationship(back_populates="users", link_model=LinkGroupUser, sa_relationship_kwargs={"lazy": "selectin"})

sqlmodel.Field sqlmodel.DateTime sqlmodel.Relationship
[((369, 436), 'sqlmodel.Field', 'Field', ([], {'nullable': '(True)', 'index': '(True)', 'sa_column_kwargs': "{'unique': True}"}), "(nullable=True, index=True, sa_column_kwargs={'unique': True})\n", (374, 436), False, 'from sqlmodel import Field, SQLModel, Relationship, Column, DateTime\n'), ((463, 482), 'sqlmodel.Field', 'Field', ([], {'default': '(True)'}), '(default=True)\n', (468, 482), False, 'from sqlmodel import Field, SQLModel, Relationship, Column, DateTime\n'), ((508, 528), 'sqlmodel.Field', 'Field', ([], {'default': '(False)'}), '(default=False)\n', (513, 528), False, 'from sqlmodel import Field, SQLModel, Relationship, Column, DateTime\n'), ((842, 875), 'sqlmodel.Field', 'Field', ([], {'nullable': '(False)', 'index': '(True)'}), '(nullable=False, index=True)\n', (847, 875), False, 'from sqlmodel import Field, SQLModel, Relationship, Column, DateTime\n'), ((920, 962), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'foreign_key': '"""role.id"""'}), "(default=None, foreign_key='role.id')\n", (925, 962), False, 'from sqlmodel import Field, SQLModel, Relationship, Column, DateTime\n'), ((992, 1077), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""users"""', 'sa_relationship_kwargs': "{'lazy': 'selectin'}"}), "(back_populates='users', sa_relationship_kwargs={'lazy':\n    'selectin'})\n", (1004, 1077), False, 'from sqlmodel import Field, SQLModel, Relationship, Column, DateTime\n'), ((1102, 1213), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""users"""', 'link_model': 'LinkGroupUser', 'sa_relationship_kwargs': "{'lazy': 'selectin'}"}), "(back_populates='users', link_model=LinkGroupUser,\n    sa_relationship_kwargs={'lazy': 'selectin'})\n", (1114, 1213), False, 'from sqlmodel import Field, SQLModel, Relationship, Column, DateTime\n'), ((588, 611), 'sqlmodel.DateTime', 'DateTime', ([], {'timezone': '(True)'}), '(timezone=True)\n', (596, 611), False, 'from sqlmodel import Field, SQLModel, Relationship, Column, DateTime\n')]