from __future__ import annotations

from typing import Any, Literal

from pydantic import BaseModel, Field


class Resource(BaseModel):
    resource_id: str | None = None
    id: str | None = None
    url: str | None = None
    storage_url: str | None = None
    type: str | None = None
    resource_type: str | None = None
    metadata: dict[str, Any] = Field(default_factory=dict)


class InferenceRequest(BaseModel):
    job_id: str | None = None
    resource: Resource
    scenes: list[str] = Field(default_factory=list)
    roi: dict[str, Any] | None = None
    model_policy: dict[str, Any] | None = None
    model_group: str | None = None
    model_version: str | None = None
    parameters: dict[str, Any] = Field(default_factory=dict)
    deployment_id: str | None = None


class InferenceResult(BaseModel):
    scene: str
    category: str
    confidence: float
    geometry: dict[str, Any]
    measurements: dict[str, Any] = Field(default_factory=dict)
    attributes: dict[str, Any] = Field(default_factory=dict)
    model_name: str
    model_version: str = "v1.0.0"


class InferenceResponse(BaseModel):
    job_id: str | None = None
    model: dict[str, str]
    results: list[InferenceResult]


class ModelTestInferenceRequest(BaseModel):
    model_group: str
    model_version: str
    resource: Resource
    scenes: list[str] = Field(default_factory=list)
    parameters: dict[str, Any] = Field(default_factory=dict)
    deployment_id: str | None = None


class ModelTestInferenceResponse(BaseModel):
    model: dict[str, str]
    parameter_snapshot: dict[str, Any]
    results: list[InferenceResult]


class HealthResponse(BaseModel):
    status: Literal["ok"]
