"""Flask CLI commands for maintenance tasks."""
import click
from flask import current_app
from app.services.image_service import cleanup_orphaned_files


def register_commands(app):
    """Register custom Flask commands."""
    
    @app.cli.command('cleanup-orphaned-files')
    def cleanup_orphaned_files_command():
        """Clean up orphaned image files that have no database records."""
        click.echo('Starting orphaned file cleanup...')
        
        with app.app_context():
            result = cleanup_orphaned_files()
            
            if result['success']:
                click.echo(f"✓ {result['message']}")
            else:
                click.echo(f"✗ {result['message']}", err=True)