from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, Float, Text
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from ..database import Base


class WithdrawalRequest(Base):
    """Track withdrawal requests from users"""
    __tablename__ = "withdrawal_requests"

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id"), nullable=False)

    # Amount details
    amount = Column(Float, nullable=False)  # Requested withdrawal amount
    tax_withheld = Column(Float, default=0)  # Tax amount withheld (3.3%)
    net_amount = Column(Float, nullable=False)  # Net amount after tax

    # Bank info (snapshot at time of request)
    bank_name = Column(String(50), nullable=False)
    bank_account = Column(String(100), nullable=False)
    account_holder = Column(String(100), nullable=False)

    # Status
    status = Column(String(20), default="pending")  # pending, approved, completed, rejected

    # Admin notes
    admin_note = Column(Text, nullable=True)

    # Timestamps
    requested_at = Column(DateTime(timezone=True), server_default=func.now())
    processed_at = Column(DateTime(timezone=True), nullable=True)

    # Relationships
    user = relationship("User", backref="withdrawal_requests")
