"""
Flask routes for session management.

Provides REST API endpoints for checking session status and logging out.
"""
from flask import Blueprint, jsonify, session

session_bp = Blueprint('session', __name__)


@session_bp.route('/api/session/status')
def session_status():
    """
    Return current session status.

    Returns:
        JSON response with authentication status and user info if authenticated.

    Example response (authenticated):
        {"authenticated": true, "user": "jsmith", "environment": "prod", ...}

    Example response (not authenticated):
        {"authenticated": false}
    """
    token_data = session.get('token_data')
    if token_data:
        return jsonify({
            'authenticated': True,
            'user': token_data.get('user_data'),
            'environment': token_data.get('environment'),
            'token_expires': token_data.get('token_expires'),
            'session_created_at': session.get('session_created_at'),
            'last_activity': session.get('last_activity'),
        })
    return jsonify({'authenticated': False})


@session_bp.route('/api/session/logout', methods=['POST'])
def logout():
    """
    Clear session data (logout).

    Returns:
        JSON response confirming logout.
    """
    session.clear()
    return jsonify({'status': 'logged_out'})
