Files
aiform_prod/backend/app/api/models.py

80 lines
3.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Pydantic модели для API
"""
from pydantic import BaseModel, Field, field_validator
from typing import Optional, List
from datetime import date
class SMSSendRequest(BaseModel):
"""Запрос на отправку SMS кода"""
phone: str = Field(..., description="Номер телефона в формате +79001234567")
@field_validator('phone')
@classmethod
def validate_phone(cls, v: str) -> str:
# Убираем все кроме цифр и +
clean = ''.join(c for c in v if c.isdigit() or c == '+')
if not clean.startswith('+'):
clean = '+' + clean
if len(clean) != 12: # +7 + 10 цифр
raise ValueError('Неверный формат телефона')
return clean
class SMSVerifyRequest(BaseModel):
"""Запрос на проверку SMS кода"""
phone: str = Field(..., description="Номер телефона")
code: str = Field(..., min_length=6, max_length=6, description="6-значный код")
class ClaimCreateRequest(BaseModel):
"""Запрос на создание заявки"""
# Шаг 1: Основная информация
phone: str
email: Optional[str] = None
inn: Optional[str] = None
policy_number: str
policy_series: Optional[str] = None
# Шаг 2: Данные о происшествии
incident_date: Optional[str] = None
incident_description: Optional[str] = None
transport_type: Optional[str] = None # "air", "train", "bus", etc.
# Шаг 3: Данные для выплаты
payment_method: str = "sbp" # "sbp", "card", "bank_transfer"
bank_id: Optional[str] = None # ID банка из NSPK API (bankid)
bank_name: Optional[str] = None # Название банка для отображения
card_number: Optional[str] = None
account_number: Optional[str] = None
# Файлы (UUID после загрузки)
uploaded_files: Optional[List[str]] = []
# Метаданные
source: str = "web_form"
class ClaimResponse(BaseModel):
"""Ответ после создания заявки"""
success: bool
claim_id: Optional[str] = None
claim_number: Optional[str] = None
message: str
class TicketFormDescriptionRequest(BaseModel):
"""Отправка свободного описания проблемы (Ticket Form)"""
session_id: str = Field(..., description="ID клиентской сессии")
claim_id: Optional[str] = Field(None, description="ID заявки (если уже создана)")
phone: Optional[str] = Field(None, description="Номер телефона заявителя")
email: Optional[str] = Field(None, description="Email заявителя")
unified_id: Optional[str] = Field(None, description="Unified ID пользователя из PostgreSQL")
contact_id: Optional[str] = Field(None, description="Contact ID пользователя в CRM")
problem_description: str = Field(..., min_length=10, description="Свободное описание ситуации")
source: str = Field("ticket_form", description="Источник события")
channel: Optional[str] = Field(None, description="Переопределение Redis канала (опционально)")
entry_channel: Optional[str] = Field(None, description="Канал входа: telegram | max | web — для роутинга в n8n")