from temporalio import activity



@activity.defn
async def update_equipment_for_simulation_activity(params: dict):
    # ✅ Import inside the activity function
    from src.aeros_equipment.service import update_equipment_for_simulation
    from src.database.core import async_session, async_aeros_session
    
    
    async with async_session() as db_session, async_aeros_session() as aeros_db_session:
        return await update_equipment_for_simulation(
            db_session=db_session,
            aeros_db_session=aeros_db_session,
            project_name=params["projectName"],
            overhaul_duration=params["OverhaulDuration"],
            overhaul_interval=params["OverhaulInterval"],
            offset=params["OffSet"],
            schematic_name=params["SchematicName"],
            custom_input=params["CustomInput"],
            simulation_duration=params["SimDuration"]
        )


@activity.defn
async def execute_simulation_activity(params: dict):
    from src.database.core import async_session
    from src.aeros_simulation.simulation_save_service import execute_simulation
    async with async_session() as db_session:
        return await execute_simulation(
            db_session=db_session,
            simulation_id=params["sim_data"]["HubCnnId"],
            sim_data=params["sim_data"],
            is_saved=True,
            eq_update=params["eq_update"]
        )


@activity.defn
async def calculate_plant_eaf_activity(params: dict):
    from src.aeros_simulation.simulation_save_service import calculate_plant_eaf
    from src.database.core import async_session
    
    async with async_session() as db_session:
        return await calculate_plant_eaf(
            db_session=db_session,
            simulation_id=params["HubCnnId"],
            mo_downtime=params["MaintenanceOutages"],
            po_downtime=params["OverhaulDuration"],
            oh_interval=params["OverhaulInterval"],
            offset=params["OffSet"]
        )
        

@activity.defn
async def update_contribution_bulk_mappings_activity(sim_id: str):
    from src.aeros_contribution.service import update_contribution_bulk_mappings
    from src.database.core import async_session
    
    async with async_session() as db_session:
        return await update_contribution_bulk_mappings(
            db_session=db_session,
            simulation_id=sim_id,
        )