from datetime import timedelta
from temporalio import workflow

from temporal.activity import calculate_plant_eaf_activity, execute_simulation_activity, update_contribution_bulk_mappings_activity, update_equipment_for_simulation_activity



@workflow.defn
class SimulationWorkflow:
    @workflow.run
    async def run(self, sim_data: dict) -> str:
        # 1. Update equipment
        results = await workflow.execute_activity(
            update_equipment_for_simulation_activity,
            {**sim_data},  # ✅ one positional argument
            start_to_close_timeout=timedelta(days=1)
        )

        # 2. Execute simulation
        await workflow.execute_activity(
            execute_simulation_activity,
            {"sim_data": sim_data, "eq_update": results},
            start_to_close_timeout=timedelta(days=1)
        )

        # 3. Calculate EAF
        await workflow.execute_activity(
            calculate_plant_eaf_activity,
            sim_data,
            start_to_close_timeout=timedelta(days=1)
        )
        
        await workflow.execute_activity(
            update_contribution_bulk_mappings_activity,
            sim_data["HubCnnId"],
            start_to_close_timeout=timedelta(days=1)
        )

        # etc…
        return sim_data["HubCnnId"]  # simulation_id
