import datetime
from collections.abc import Awaitable, Callable, Sequence
from typing import Any

from csirtmu.core.temporal import TemporalWorkflow
from temporalio import workflow

from csirtmu.perun_sync.alias_sync.activities import AliasSyncActivities
from csirtmu.perun_sync.config import AppConfig


class AliasSyncWorkflow(TemporalWorkflow):
    @classmethod
    def get_activities(cls) -> Sequence[Callable[..., Awaitable[Any]]]:
        c = AppConfig.get()
        return AliasSyncActivities(c.alias_sync, c.database).get_activities()

    @workflow.run
    async def run(self) -> None:
        c = AppConfig.get()
        await workflow.execute_activity(
            AliasSyncActivities.sync,
            args=(),
            start_to_close_timeout=datetime.timedelta(minutes=20),
            retry_policy=c.temporal.retry_policy,
        )
