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


class DealerApplicationCreate(BaseModel):
    """Schema for creating a dealer application"""
    business_name: str
    business_number: Optional[str] = None
    real_name: str
    id_number: Optional[str] = None  # Will be encrypted before storage
    phone: str
    bank_name: str
    bank_account: str
    account_holder: str
    photo_url: Optional[str] = None


class DealerApplicationResponse(BaseModel):
    """Schema for dealer application response"""
    id: int
    user_id: int
    business_name: str
    business_number: Optional[str] = None
    real_name: str
    phone: str
    bank_name: str
    bank_account: str
    account_holder: str
    photo_url: Optional[str] = None
    status: str
    rejected_reason: Optional[str] = None
    applied_at: datetime
    approved_at: Optional[datetime] = None

    class Config:
        from_attributes = True


class DealerApplicationApprove(BaseModel):
    """Schema for approving a dealer application"""
    pass  # No additional fields needed


class DealerApplicationReject(BaseModel):
    """Schema for rejecting a dealer application"""
    reason: str


class DealerInfoResponse(BaseModel):
    """Schema for dealer info response"""
    id: int
    user_id: int
    dealer_code: str
    dealer_card_url: Optional[str] = None
    business_name: str
    real_name: str
    phone: str
    photo_url: Optional[str] = None
    total_commission_earned: float
    total_withdrawn: float
    pending_withdrawal: float
    is_active: bool
    created_at: datetime

    class Config:
        from_attributes = True


class DealerPublicInfo(BaseModel):
    """Public dealer info for displaying in lists"""
    id: int
    dealer_code: str
    business_name: str
    real_name: str
    photo_url: Optional[str] = None
    is_active: bool

    class Config:
        from_attributes = True
