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


class VehicleShareCreate(BaseModel):
    """Schema for creating a vehicle share"""
    request_vehicle_id: int
    markup_amount_krw: float = 0


class VehicleShareResponse(BaseModel):
    """Schema for vehicle share response"""
    id: int
    user_id: int
    request_vehicle_id: int
    share_code: str
    original_price_krw: float
    markup_amount_krw: float
    shared_price_krw: float
    view_count: int
    is_purchased: bool
    purchased_by_user_id: Optional[int] = None
    created_at: datetime
    expires_at: Optional[datetime] = None
    purchased_at: Optional[datetime] = None

    class Config:
        from_attributes = True


class VehicleSharePublic(BaseModel):
    """Public schema for shared vehicle (for viewing shared link)"""
    id: int
    share_code: str
    shared_price_krw: float
    view_count: int
    is_purchased: bool
    created_at: datetime
    # Vehicle info will be added separately

    class Config:
        from_attributes = True


class ShareRewardResponse(BaseModel):
    """Schema for share reward response"""
    id: int
    user_id: int
    vehicle_share_id: int
    markup_amount: float
    reward_amount: float
    tax_amount: float
    net_amount: float
    status: str
    withdrawn_at: Optional[datetime] = None
    created_at: datetime

    class Config:
        from_attributes = True


class ShareRewardSummary(BaseModel):
    """Summary of user's share rewards"""
    total_rewards: float
    total_withdrawn: float
    pending_amount: float
    available_for_withdrawal: float
    reward_count: int
