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ing import Optional, List
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from uuid import UUID
|
| 5 |
+
from decimal import Decimal
|
| 6 |
+
|
| 7 |
+
# Auth Schemas
|
| 8 |
+
class Token(BaseModel):
|
| 9 |
+
access_token: str
|
| 10 |
+
token_type: str
|
| 11 |
+
|
| 12 |
+
class TokenData(BaseModel):
|
| 13 |
+
user_id: Optional[UUID] = None
|
| 14 |
+
|
| 15 |
+
# User Schemas
|
| 16 |
+
class UserBase(BaseModel):
|
| 17 |
+
username: str
|
| 18 |
+
email: EmailStr
|
| 19 |
+
name: Optional[str] = None
|
| 20 |
+
|
| 21 |
+
class UserCreate(UserBase):
|
| 22 |
+
password: str
|
| 23 |
+
|
| 24 |
+
class UserLogin(BaseModel):
|
| 25 |
+
email: EmailStr
|
| 26 |
+
password: str
|
| 27 |
+
|
| 28 |
+
class UserUpdate(BaseModel):
|
| 29 |
+
name: Optional[str] = None
|
| 30 |
+
avatar_url: Optional[str] = None
|
| 31 |
+
timezone: Optional[str] = None
|
| 32 |
+
currency: Optional[str] = None
|
| 33 |
+
|
| 34 |
+
class User(UserBase):
|
| 35 |
+
id: UUID
|
| 36 |
+
balance: Decimal
|
| 37 |
+
role: str
|
| 38 |
+
status: str
|
| 39 |
+
created_at: datetime
|
| 40 |
+
|
| 41 |
+
class Config:
|
| 42 |
+
from_attributes = True
|
| 43 |
+
|
| 44 |
+
# Category Schemas
|
| 45 |
+
class CategoryBase(BaseModel):
|
| 46 |
+
name: str
|
| 47 |
+
slug: str
|
| 48 |
+
description: Optional[str] = None
|
| 49 |
+
icon: Optional[str] = None
|
| 50 |
+
sort_order: int = 0
|
| 51 |
+
is_active: bool = True
|
| 52 |
+
|
| 53 |
+
class Category(CategoryBase):
|
| 54 |
+
id: int
|
| 55 |
+
|
| 56 |
+
class Config:
|
| 57 |
+
from_attributes = True
|
| 58 |
+
|
| 59 |
+
# Service Schemas
|
| 60 |
+
class ServiceBase(BaseModel):
|
| 61 |
+
category_id: int
|
| 62 |
+
name: str
|
| 63 |
+
description: Optional[str] = None
|
| 64 |
+
price_per_1000: Decimal
|
| 65 |
+
min_quantity: int
|
| 66 |
+
max_quantity: int
|
| 67 |
+
average_time: Optional[str] = None
|
| 68 |
+
status: str = "active"
|
| 69 |
+
|
| 70 |
+
class Service(ServiceBase):
|
| 71 |
+
id: int
|
| 72 |
+
|
| 73 |
+
class Config:
|
| 74 |
+
from_attributes = True
|
| 75 |
+
# Order Schemas
|
| 76 |
+
class OrderBase(BaseModel):
|
| 77 |
+
service_id: int
|
| 78 |
+
link: str
|
| 79 |
+
quantity: int
|
| 80 |
+
|
| 81 |
+
class OrderCreate(OrderBase):
|
| 82 |
+
pass
|
| 83 |
+
|
| 84 |
+
class Order(OrderBase):
|
| 85 |
+
id: int
|
| 86 |
+
user_id: UUID
|
| 87 |
+
charge: Decimal
|
| 88 |
+
status: str
|
| 89 |
+
start_count: int
|
| 90 |
+
remains: int
|
| 91 |
+
created_at: datetime
|
| 92 |
+
updated_at: datetime
|
| 93 |
+
|
| 94 |
+
class Config:
|
| 95 |
+
from_attributes = True
|
| 96 |
+
|
| 97 |
+
# Transaction Schemas
|
| 98 |
+
class TransactionBase(BaseModel):
|
| 99 |
+
amount: Decimal
|
| 100 |
+
type: str
|
| 101 |
+
payment_method: str
|
| 102 |
+
note: Optional[str] = None
|
| 103 |
+
|
| 104 |
+
class TransactionCreate(TransactionBase):
|
| 105 |
+
pass
|
| 106 |
+
|
| 107 |
+
class Transaction(TransactionBase):
|
| 108 |
+
id: UUID
|
| 109 |
+
user_id: UUID
|
| 110 |
+
status: str
|
| 111 |
+
balance_before: Optional[Decimal] = None
|
| 112 |
+
balance_after: Optional[Decimal] = None
|
| 113 |
+
created_at: datetime
|
| 114 |
+
|
| 115 |
+
class Config:
|
| 116 |
+
from_attributes = True
|
| 117 |
+
|
| 118 |
+
# Ticket Schemas
|
| 119 |
+
class TicketBase(BaseModel):
|
| 120 |
+
subject: str
|
| 121 |
+
priority: str = "Normal"
|
| 122 |
+
order_id: Optional[int] = None
|
| 123 |
+
|
| 124 |
+
class TicketCreate(TicketBase):
|
| 125 |
+
message: str
|
| 126 |
+
|
| 127 |
+
class Ticket(TicketBase):
|
| 128 |
+
id: int
|
| 129 |
+
user_id: UUID
|
| 130 |
+
status: str
|
| 131 |
+
created_at: datetime
|
| 132 |
+
updated_at: datetime
|
| 133 |
+
|
| 134 |
+
class Config:
|
| 135 |
+
from_attributes = True
|
| 136 |
+
|
| 137 |
+
class TicketMessageBase(BaseModel):
|
| 138 |
+
message: str
|
| 139 |
+
|
| 140 |
+
class TicketMessageCreate(TicketMessageBase):
|
| 141 |
+
pass
|
| 142 |
+
|
| 143 |
+
class TicketMessage(TicketMessageBase):
|
| 144 |
+
id: int
|
| 145 |
+
ticket_id: int
|
| 146 |
+
user_id: UUID
|
| 147 |
+
is_admin: bool
|
| 148 |
+
created_at: datetime
|
| 149 |
+
|
| 150 |
+
class Config:
|
| 151 |
+
from_attributes = True
|