from typing import Any

from sqlalchemy.ext.declarative import (
    as_declarative,
    declared_attr
)
from sqlalchemy import (
    DateTime,
    Column
)
from sqlalchemy.sql import func


@as_declarative()
class Base:
    __name__: str

    id: Any
    created_at = Column(
        DateTime(timezone=True),
        server_default=func.now(),
        nullable=False
    )
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())

    # Generate __tablename__ automatically
    @declared_attr
    def __tablename__(cls) -> str:
        return cls.__name__.lower()
