"""Account model representing a brokerage account.""" from sqlalchemy import Column, Integer, String, DateTime, Enum from sqlalchemy.orm import relationship from sqlalchemy.sql import func import enum from app.database import Base class AccountType(str, enum.Enum): """Enumeration of account types.""" CASH = "cash" MARGIN = "margin" class Account(Base): """ Represents a brokerage account. Attributes: id: Primary key account_number: Unique account identifier account_name: Human-readable account name account_type: Type of account (cash or margin) created_at: Timestamp of account creation updated_at: Timestamp of last update transactions: Related transactions positions: Related positions """ __tablename__ = "accounts" id = Column(Integer, primary_key=True, index=True) account_number = Column(String(50), unique=True, nullable=False, index=True) account_name = Column(String(200), nullable=False) account_type = Column(Enum(AccountType), nullable=False, default=AccountType.CASH) created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False) updated_at = Column(DateTime(timezone=True), onupdate=func.now(), server_default=func.now(), nullable=False) # Relationships transactions = relationship("Transaction", back_populates="account", cascade="all, delete-orphan") positions = relationship("Position", back_populates="account", cascade="all, delete-orphan")