from flask import jsonify

def get_user_detail(request, User):
    data = request.get_json()

    query = data.get('username')
    if query:
        
        users = User.query.filter(User.username == query).all()
       
    else:
        return jsonify({"response": "error"}),404
    output = []
    

    for use in users:
        user_data = {
            'username': use.username,
            'id': use.id,
            'fullname': use.fullname,
            'profile_img_url': use.profile_img_url,
            'email': use.email,
            'contactno': use.contactno,
            'user_type': use.user_type,
            'institute_id': use.institute_id,
            'is_verified': use.is_verified,
            'last_active_at': use.last_active_at.isoformat() if use.last_active_at else None
        }
        output.append(user_data)
    
    return jsonify({'users': output}), 200
