from __future__ import annotations import click from .extensions import db from .models import BadgeDefinition from .services.monthly import archive_months_missing_up_to_previous from .services.notifications import send_due_notifications, send_monthly_winner_notifications DEFAULT_BADGES = [ { "key": "early_bird", "name": "Frühstarter", "description": "Erledige 3 Aufgaben vor ihrem Fälligkeitsdatum.", "icon_name": "bell", "trigger_type": "early_finisher_count", "threshold": 3, "bonus_points": 10, }, { "key": "on_time_streak", "name": "Sauberer Lauf", "description": "Erledige Aufgaben an 3 Tagen in Folge.", "icon_name": "check", "trigger_type": "streak_days", "threshold": 3, "bonus_points": 15, }, { "key": "task_sprinter", "name": "Putz-Sprinter", "description": "Schließe 8 Aufgaben in einem Monat ab.", "icon_name": "trophy", "trigger_type": "monthly_task_count", "threshold": 8, "bonus_points": 20, }, ] def seed_badges() -> None: for payload in DEFAULT_BADGES: badge = BadgeDefinition.query.filter_by(key=payload["key"]).first() if not badge: db.session.add(BadgeDefinition(**payload)) db.session.commit() def register_cli(app) -> None: @app.cli.command("init-db") def init_db_command(): db.create_all() seed_badges() click.echo("Datenbank und Standard-Badges sind bereit.") @app.cli.command("archive-months") def archive_months_command(): archive_months_missing_up_to_previous() click.echo("Monatsarchiv wurde geprüft.") @app.cli.command("notify-due") def notify_due_command(): result = send_due_notifications() click.echo(f"Due-Push: sent={result.sent} skipped={result.skipped} failed={result.failed}") @app.cli.command("notify-monthly-winner") def notify_monthly_winner_command(): result = send_monthly_winner_notifications() click.echo(f"Winner-Push: sent={result.sent} skipped={result.skipped} failed={result.failed}")