from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey
from typing import List, Optional
from sqlmodel import SQLModel, Field, Relationship, VARCHAR, Column
from pydantic import EmailStr


class UserGroup(SQLModel, table=True):
    id: int = Field(default=None, primary_key=True)
    name: str

    users: List["User"] = Relationship(back_populates="group")


class User(SQLModel, table=True):
    id: int = Field(default=None, primary_key=True)
    username: str = Field(sa_column=Column('username', VARCHAR, unique=True))
    email: EmailStr
    password: str
    first_name: str
    last_name: str
    public_key: str
    private_key: str
    profile_pic: Optional[str]
    is_staff: bool = Field(default=False)

    group_id: Optional[int] = Field(foreign_key="usergroup.id")
    group: Optional[UserGroup] = Relationship(back_populates="users")


class RemoteUser(SQLModel, table=True):
    id: int = Field(default=None, primary_key=True)
    remote_id: str = Field(sa_column=