from __future__ import annotations

from datetime import date
from typing import Any


class AlertServiceMixin:
    def alert_center(self, status: str = "all", as_of: str = "") -> dict[str, Any]:
        tracking = self.strategy_tracking.list_tracking(self.current_user_id, 12)
        self.alert_service.sync_strategy_tracking(self.current_user_id, tracking)
        return self.alert_service.list_alerts(
            self.current_user_id, status, as_of
        )

    def create_alert(self, payload: dict[str, Any]) -> dict[str, Any]:
        alert_id = self.alert_service.create_manual(self.current_user_id, payload)
        return {"id": alert_id, **self.alert_center()}

    def mark_alert_read(self, alert_id: int) -> dict[str, Any]:
        self.alert_service.mark_read(self.current_user_id, alert_id)
        return self.alert_center()

    def mark_all_alerts_read(self, as_of: str = "") -> dict[str, Any]:
        compact_date = self.alert_service.calendar_date(as_of or date.today().isoformat())
        self.alert_service.mark_all_read(self.current_user_id, compact_date)
        return self.alert_center(as_of=compact_date)

    def delete_alert(self, alert_id: int) -> dict[str, Any]:
        deleted = self.alert_service.delete(self.current_user_id, alert_id)
        return {"deleted": deleted, **self.alert_center()}
