from flask import Blueprint, render_template, session
from ..models import db, AuditoriaLog, Campanha
from ..utils.auth_decorators import login_required, admin_required

auditoria_bp = Blueprint('auditoria', __name__, url_prefix='/auditoria')

@auditoria_bp.route('/')
@login_required
@admin_required
def index():
    campanha_id = session.get('campanha_id')
    campanha = Campanha.query.get(campanha_id) if campanha_id else None
    
    logs = AuditoriaLog.query.order_by(AuditoriaLog.data_hora.desc()).limit(200).all()
    
    return render_template('auditoria/lista.html', logs=logs, campanha=campanha)
