import enum from datetime import datetime from sqlalchemy import Boolean, DateTime, Enum, Integer, String, func from sqlalchemy.orm import Mapped, mapped_column from app.database import Base class ServerProtocol(str, enum.Enum): OUTLINE = "outline" WIREGUARD = "wireguard" XRAY = "xray" class Server(Base): __tablename__ = "servers" id: Mapped[int] = mapped_column(Integer, primary_key=True) name: Mapped[str] = mapped_column(String(64), unique=True, nullable=False) host: Mapped[str] = mapped_column(String(255), nullable=False) port: Mapped[int] = mapped_column(Integer, nullable=False) protocol: Mapped[ServerProtocol] = mapped_column( Enum(ServerProtocol, name="server_protocol"), nullable=False ) location: Mapped[str] = mapped_column(String(128), nullable=False) country_code: Mapped[str] = mapped_column(String(4), nullable=False) load_percent: Mapped[int] = mapped_column(Integer, default=0) is_active: Mapped[bool] = mapped_column(Boolean, default=True) max_users: Mapped[int] = mapped_column(Integer, default=100) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now() ) def __repr__(self) -> str: return f""