#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
模块名称：performance_output.py
模块描述：性能测试任务输出 Pydantic Schema

作者：czj
创建日期：2026-08-13
"""

from datetime import datetime
from typing import Any, List, Optional
from pydantic import BaseModel, Field, ConfigDict


# ==================== 捕获规则 ====================

class CaptureRule(BaseModel):
    """响应捕获规则"""
    key: str = Field(..., description="输出键名")
    json_path: str = Field(..., description="JSON Path 表达式，如 $.data.messageId")
    multiple: bool = Field(True, description="是否允许多值追加")
    description: str = Field("", description="规则描述")

    model_config = ConfigDict(populate_by_name=True, from_attributes=True)


# ==================== 输出 Schema ====================

class PerformanceTaskOutputResponse(BaseModel):
    """任务输出响应"""
    id: int
    task_id: str
    key: str
    value: List[Any] = []
    created_at: Optional[str] = None

    model_config = ConfigDict(populate_by_name=True, from_attributes=True)


class PerformanceTaskOutputListResponse(BaseModel):
    """任务输出列表响应"""
    total: int
    items: List[PerformanceTaskOutputResponse]

    model_config = ConfigDict(populate_by_name=True, from_attributes=True)