"""
Main routes - Landing page, home, etc.
"""
from flask import Blueprint, render_template, redirect, url_for, session
from app import db
from app.models import User, Instance

main_bp = Blueprint('main', __name__)


@main_bp.route('/')
def index():
    """Landing page"""
    # Check if user is logged in
    if session.get('user_id'):
        return redirect(url_for('dashboard.index'))
    return render_template('index.html')


@main_bp.route('/pricing')
def pricing():
    """Pricing page"""
    return render_template('pricing.html')


@main_bp.route('/features')
def features():
    """Features page"""
    return render_template('features.html')


@main_bp.route('/about')
def about():
    """About page"""
    return render_template('about.html')


@main_bp.route('/docs')
def docs():
    """Documentation page"""
    return render_template('docs.html')


@main_bp.route('/health')
def health():
    """Health check endpoint"""
    try:
        # Test database connection
        db.session.execute(db.text('SELECT 1'))
        return {'status': 'healthy', 'database': 'connected'}, 200
    except Exception as e:
        return {'status': 'unhealthy', 'error': str(e)}, 503
