import sqlite3

conn = sqlite3.connect('school_classes.db')
cursor = conn.cursor()

cursor.execute('''CREATE TABLE IF NOT EXISTS classes (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    class_name TEXT NOT NULL,
    classroom TEXT NOT NULL,
    parent_room TEXT NOT NULL,
    teacher_name TEXT NOT NULL,
    internal_number TEXT NOT NULL,
    mobile_number TEXT NOT NULL
)''')

conn.commit()
print("✅ School classes database and table created successfully ready for you to insert data!")

def search_teacher(search_term):
    """
    Search for teachers by name (even partial name)
    and display their information
    """
    # Connect to database
    conn = sqlite3.connect('school_classes.db')
    cursor = conn.cursor()
    
    # Use LIKE with wildcards for partial search
    query = """
    SELECT * FROM classes 
    WHERE teacher_name LIKE ? 
    ORDER BY teacher_name
    """
    
    # Add wildcards for partial matching
    search_with_wildcards = f"%{search_term}%"
    
    # Execute search
    cursor.execute(query, (search_with_wildcards,))
    results = cursor.fetchall()
    
    # Display results
    if results:
        print(f"\n🔍 Found {len(results)} teacher(s) matching '{search_term}':")
        print("=" * 60)
        for teacher in results:
            print(f"\n📚 {teacher[4]}")  # teacher_name
            print(f"   Class: {teacher[1]}")  # class_name
            print(f"   Classroom: {teacher[2]}")  # classroom
            print(f"   Parent Room: {teacher[3]}")  # parent_room
            print(f"   Internal: {teacher[5]}")  # internal_number
            print(f"   Mobile: {teacher[6]}")  # mobile_number
            print("-" * 40)
    else:
        print(f"\n❌ No teachers found containing '{search_term}'")
    
    # Close connection
    conn.close()

# Example usage
if __name__ == "__main__":
    # Get search term from user
    search_input = input("Enter teacher name to search: ").strip()
    
    if search_input:
        search_teacher(search_input)
    else:
        print("❌ Please enter a search term")
