# Copyright 2026 ResQ
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""DTSOP domain models for the ResQ MCP server."""

from __future__ import annotations

from typing import Literal

from pydantic import BaseModel


class SimulationRequest(BaseModel):
    """Request for high-fidelity physics simulation in digital twin.

    Part of DTSOP system. Triggers physics-based simulation in Unity/Unreal
    Engine for accurate disaster propagation modeling and strategy validation.

    Attributes:
        scenario_id: Unique scenario identifier for this simulation.
        sector_id: Geographic sector to simulate.
        disaster_type: Type of disaster to model (e.g., "flood", "wildfire").
        parameters: Simulation parameters (e.g., {"wind_speed": 15.5, "water_level": 2.3}).
        priority: Processing priority (standard queued, urgent fast-tracked).

    Note:
        Simulations run asynchronously. Monitor progress via the returned
        simulation ID and resource subscription (resq://simulations/{id}).
    """

    scenario_id: str
    sector_id: str
    disaster_type: str
    parameters: dict[str, float | str]  # e.g., wind_speed, water_level
    priority: Literal["standard", "urgent"] = "standard"


class OptimizationStrategy(BaseModel):
    """Reinforcement learning-optimized deployment and evacuation strategy.

    Part of DTSOP system. Generated by RL agents trained on thousands of
    simulated disaster scenarios to optimize resource allocation and
    evacuation routing under various constraints.

    Attributes:
        strategy_id: Unique strategy identifier (e.g., "STRAT-X1Y2Z3W4").
        related_alert_id: Pre-alert or incident ID this strategy addresses.
        recommended_deployment: Mapping of drone types to recommended counts
                                (e.g., {"surveillance": 2, "payload": 1}).
        evacuation_routes: Ordered list of recommended evacuation routes.
        estimated_success_rate: Predicted success probability (0.0 to 1.0)
                                based on simulation outcomes.
        simulation_proof_url: NeoFS/IPFS URL for simulation evidence and logs.

    Note:
        Success rate derived from Monte Carlo simulations across varying
        disaster intensities and communication scenarios.
    """

    strategy_id: str
    related_alert_id: str | None = None
    recommended_deployment: dict[str, int]  # drone_type -> count
    evacuation_routes: list[str]
    estimated_success_rate: float
    simulation_proof_url: str | None = None
