# -*- coding: utf-8 -*-
"""业务运行上下文 API Schema。"""

from __future__ import annotations

from datetime import date, datetime
from typing import Literal

from pydantic import BaseModel, Field


RuntimeMode = Literal["live", "sandbox"]
AIMode = Literal["live"]


class RuntimeContextResponse(BaseModel):
    site_id: int
    mode: RuntimeMode
    business_day_start_hour: int
    business_date: date
    business_now: datetime
    sandbox_date: date | None = None
    sandbox_instance_id: str | None = None
    ai_mode: AIMode = "live"
    status: str = "active"
    is_sandbox: bool = False


class RuntimeTransitionStep(BaseModel):
    key: str
    title: str
    status: Literal["success", "skipped", "warning", "failed"]
    detail: str = ""
    count: int = 0


class RuntimeSwitchRequest(BaseModel):
    site_id: int = Field(..., ge=1)
    mode: RuntimeMode
    sandbox_date: date | None = None
    reset_sandbox: bool = True
    reason: str | None = Field(default=None, max_length=500)


class RuntimeSwitchResponse(BaseModel):
    context: RuntimeContextResponse
    steps: list[RuntimeTransitionStep]

