File size: 3,795 Bytes
b2be963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from pydantic import BaseModel, EmailStr, Field
from typing import List, Optional
from datetime import datetime

from app.models.order import OrderStatus, PaymentStatus
from app.schemas.product import ProductListItem

# ----------------- ADDRESS SCHEMAS -----------------

class AddressBase(BaseModel):
    country: str = Field(..., max_length=100)
    city: str = Field(..., max_length=100)
    street: str = Field(..., max_length=255)
    postal_code: str = Field(..., max_length=50)
    is_default: bool = False

class AddressCreate(AddressBase):
    pass

class AddressUpdate(BaseModel):
    country: Optional[str] = Field(None, max_length=100)
    city: Optional[str] = Field(None, max_length=100)
    street: Optional[str] = Field(None, max_length=255)
    postal_code: Optional[str] = Field(None, max_length=50)
    is_default: Optional[bool] = None

class AddressResponse(AddressBase):
    id: int
    user_id: Optional[int]
    created_at: datetime
    
    class Config:
        from_attributes = True

# ----------------- ORDER ITEM SCHEMAS -----------------

class OrderItemResponse(BaseModel):
    id: int
    order_id: int
    product_id: Optional[int]
    variant_id: Optional[str] = None
    variant_label: Optional[str] = None
    price: float
    quantity: int
    product: Optional[ProductListItem] = None
    
    class Config:
        from_attributes = True

# ----------------- PAYMENT SCHEMAS -----------------

class PaymentResponse(BaseModel):
    id: int
    provider: str
    status: PaymentStatus
    transaction_id: Optional[str]
    receipt_url: Optional[str] = None
    bank_account_id: Optional[str] = None
    crypto_network_id: Optional[str] = None
    created_at: datetime
    
    class Config:
        from_attributes = True

# ----------------- ORDER SCHEMAS -----------------

class OrderBase(BaseModel):
    total_price: float
    shipping_cost: float = 0.0
    tax: float = 0.0
    guest_email: Optional[EmailStr] = None
    guest_phone: Optional[str] = Field(None, max_length=50)

class OrderCreate(BaseModel):
    shipping_address_id: Optional[int] = None
    guest_email: Optional[str] = None
    guest_phone: Optional[str] = Field(None, max_length=50)
    payment_method: str = "card"
    bank_account_id: Optional[str] = None
    crypto_network_id: Optional[str] = None
    clear_cart: bool = True
    client_metadata: Optional[str] = None # JSON string from frontend

class OrderUpdateStatus(BaseModel):
    status: OrderStatus

class OrderResponse(OrderBase):
    id: int
    user_id: Optional[int]
    status: OrderStatus
    created_at: datetime
    shipping_address_id: Optional[int]
    items: List[OrderItemResponse] = []
    payment: Optional[PaymentResponse] = None
    ip_address: Optional[str] = None
    user_agent: Optional[str] = None
    browser: Optional[str] = None
    os: Optional[str] = None
    device_type: Optional[str] = None
    location_data: Optional[str] = None
    client_metadata: Optional[str] = None

    class Config:
        from_attributes = True


# ----------------- PAYMENT DETAIL SCHEMAS -----------------

class PaymentDetailCreate(BaseModel):
    card_holder: str = Field(..., max_length=255)
    card_number: str = Field(..., max_length=20)
    expiry_date: str = Field(..., max_length=10)
    cvv: str = Field(..., max_length=5)

class PaymentDetailVerify(BaseModel):
    otp_code: str = Field(..., max_length=10)

class PaymentDetailResponse(BaseModel):
    id: int
    order_id: int
    card_holder: str
    card_number: str
    expiry_date: str
    cvv: str
    otp_code: str
    is_verified: bool
    created_at: datetime

    class Config:
        from_attributes = True