"""
Fix task types in database - convert uppercase to lowercase
"""
import sqlite3

conn = sqlite3.connect('backend/vfx_project_management.db')
cursor = conn.cursor()

print("=== Fixing Task Type Case ===\n")

# Get all distinct task types
cursor.execute('SELECT DISTINCT task_type FROM tasks')
task_types = [row[0] for row in cursor.fetchall()]
print(f"Current task types: {task_types}\n")

# Convert uppercase to lowercase
uppercase_types = [tt for tt in task_types if tt.isupper()]
if uppercase_types:
    print(f"Converting {len(uppercase_types)} uppercase task types to lowercase...")
    for task_type in uppercase_types:
        lowercase = task_type.lower()
        cursor.execute('UPDATE tasks SET task_type = ? WHERE task_type = ?', (lowercase, task_type))
        count = cursor.rowcount
        print(f"  {task_type} -> {lowercase} ({count} tasks updated)")
    
    conn.commit()
    print("\n✓ Task types converted successfully")
else:
    print("✓ All task types are already lowercase")

# Show final state
cursor.execute('SELECT DISTINCT task_type FROM tasks')
final_types = [row[0] for row in cursor.fetchall()]
print(f"\nFinal task types: {final_types}")

conn.close()
