from datetime import datetime
from typing import Optional, Dict, List

import matplotlib

matplotlib.use("Agg")

from fastapi import FastAPI, UploadFile, File, HTTPException, BackgroundTasks
from fastapi.responses import FileResponse, StreamingResponse
from pydantic import BaseModel, Field

class StartSessionRequest(BaseModel):
    file_raw_id: str = Field(..., description="id загруженного .mat/.h5")
    file_json_id: str = Field(..., description="id загруженного JSON с параметрами")
    file_order_id: Optional[str] = Field(None, description="id JSON с порядком k-space (для nonlinear/radial)")
    sequence_name: str = Field(..., description="linear_decart | nonlinear_decart(tse) | linear_epi | radial_propeller")
    digit: str = Field(..., description="'2d' или '3d'")
    phase_shift: bool = Field(False, description="включать RF-spoil из JSON или обнулить")


class SessionStatus(BaseModel):
    session_id: str
    status: str  # queued | running | done | error
    progress: float
    message: str
    created_at: str
    updated_at: str
    result_files: List[str] = []
    error_traceback: Optional[str] = None

