from pydantic import BaseModel
from typing import Optional
from datetime import datetime


class WithdrawalRequestCreate(BaseModel):
    """Schema for creating a withdrawal request"""
    amount: float
    bank_name: str
    bank_account: str
    account_holder: str


class WithdrawalRequestResponse(BaseModel):
    """Schema for withdrawal request response"""
    id: int
    user_id: int
    amount: float
    tax_withheld: float
    net_amount: float
    bank_name: str
    bank_account: str
    account_holder: str
    status: str
    admin_note: Optional[str] = None
    requested_at: datetime
    processed_at: Optional[datetime] = None

    class Config:
        from_attributes = True


class WithdrawalProcess(BaseModel):
    """Schema for processing a withdrawal (admin)"""
    status: str  # approved, completed, rejected
    admin_note: Optional[str] = None


class WithdrawalBalance(BaseModel):
    """Schema for user's withdrawal balance"""
    total_earned: float  # Total earnings (dealer commission + share rewards)
    total_withdrawn: float  # Total already withdrawn
    pending_withdrawal: float  # Currently pending withdrawal requests
    available_balance: float  # Available for withdrawal
