from __future__ import annotations

import time

from .base import ProviderResult, TaskProvider


class MockTaskProvider(TaskProvider):
    name = "mock"

    def healthcheck(self, config: dict) -> ProviderResult:
        return ProviderResult(ok=True, payload={"provider": self.name})

    def create_task(self, config: dict, payload: dict) -> ProviderResult:
        ext = (
            str(payload.get("external_key") or "") or f"mock-{int(time.time() * 1000)}"
        )
        return ProviderResult(
            ok=True, external_key=ext, payload={"action": "create_task"}
        )

    def append_update(self, config: dict, payload: dict) -> ProviderResult:
        return ProviderResult(
            ok=True,
            external_key=str(payload.get("external_key") or ""),
            payload={"action": "append_update"},
        )

    def mark_complete(self, config: dict, payload: dict) -> ProviderResult:
        return ProviderResult(
            ok=True,
            external_key=str(payload.get("external_key") or ""),
            payload={"action": "mark_complete"},
        )

    def link_task(self, config: dict, payload: dict) -> ProviderResult:
        return ProviderResult(
            ok=True,
            external_key=str(payload.get("external_key") or ""),
            payload={"action": "link_task"},
        )
