from datetime import datetime
from typing import Optional

from pydantic import Field

from letta.constants import DEFAULT_ORG_ID
from letta.schemas.enums import PrimitiveType
from letta.schemas.letta_base import LettaBase
from letta.validators import UserId


class UserBase(LettaBase):
    __id_prefix__ = PrimitiveType.USER.value


class User(UserBase):
    """Representation of a user."""

    id: str = UserBase.generate_id_field()
    organization_id: Optional[str] = Field(DEFAULT_ORG_ID, description="The organization id of the user")
    name: str = Field(..., description="The name of the user.")
    created_at: Optional[datetime] = Field(default_factory=datetime.utcnow, description="The creation date of the user.")
    updated_at: Optional[datetime] = Field(default_factory=datetime.utcnow, description="The update date of the user.")
    is_deleted: bool = Field(False, description="Whether this user is deleted or not.")


class UserCreate(UserBase):
    name: str = Field(..., description="The name of the user.")
    organization_id: str = Field(..., description="The organization id of the user.")


class UserUpdate(UserBase):
    id: UserId = Field(..., description="The id of the user to update.")
    name: Optional[str] = Field(None, description="The new name of the user.")
    organization_id: Optional[str] = Field(None, description="The new organization id of the user.")
