import logging
from flask import render_template
from models import Preset
from services.file_io import get_available_checkpoints
from services.comfyui import get_loaded_checkpoint
from services.workflow import _get_default_checkpoint

logger = logging.getLogger('gaze')


def register_routes(app):

    @app.route('/quick')
    def quick_generator():
        presets = Preset.query.order_by(Preset.name).all()
        checkpoints = get_available_checkpoints()

        # Default to whatever is currently loaded in ComfyUI, then settings default
        selected_ckpt = get_loaded_checkpoint()
        if not selected_ckpt:
            default_path, _ = _get_default_checkpoint()
            selected_ckpt = default_path

        return render_template('quick.html', presets=presets,
                               checkpoints=checkpoints, selected_ckpt=selected_ckpt)
