"""crondag db — database management."""
from __future__ import annotations

import asyncio

import click


@click.group()
def db():
    """Database management commands."""
    pass


@db.command("init")
def db_init():
    """Initialize the database (create tables)."""
    from crondag.config import get_settings
    from crondag.models.base import init_db

    settings = get_settings()
    asyncio.run(init_db(settings.database_url))
    click.echo("Database initialized.")


@db.command("reset")
@click.confirmation_option(prompt="This will delete all data. Are you sure?")
def db_reset():
    """Reset the database (drop and recreate tables)."""
    from crondag.config import get_settings
    from crondag.models.base import reset_db

    settings = get_settings()
    asyncio.run(reset_db(settings.database_url))
    click.echo("Database reset.")
