# -*- coding: utf-8 -*-
"""执行与队列相关的 Pydantic 模型

用于 execution 路由的请求/响应序列化。
"""

from __future__ import annotations

from datetime import datetime
from typing import Any

from pydantic import BaseModel


class ReorderRequest(BaseModel):
    """队列重排请求"""
    task_id: str
    new_position: int


class QueueTaskResponse(BaseModel):
    """队列任务响应"""
    id: str
    site_id: int
    config: dict[str, Any]
    status: str
    position: int
    created_at: datetime | None = None
    started_at: datetime | None = None
    finished_at: datetime | None = None
    exit_code: int | None = None
    error_message: str | None = None


class ExecutionRunResponse(BaseModel):
    """直接执行任务的响应"""
    execution_id: str
    message: str


class ExecutionHistoryItem(BaseModel):
    """执行历史记录"""
    id: str
    site_id: int
    task_codes: list[str]
    status: str
    started_at: datetime
    finished_at: datetime | None = None
    exit_code: int | None = None
    duration_ms: int | None = None
    command: str | None = None
    summary: dict[str, Any] | None = None
    schedule_id: str | None = None


class ExecutionLogsResponse(BaseModel):
    """执行日志响应"""
    execution_id: str
    output_log: str | None = None
    error_log: str | None = None
