#!/usr/bin/env python3
"""
Debug script to check projects table and data.
"""

import sqlite3
from pathlib import Path

def debug_projects():
    """Debug projects table structure and data."""
    
    print("Debugging Projects Table")
    print("=" * 30)
    
    db_path = "vfx_project_management.db"
    
    try:
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # Check table structure
        print("1. Projects table structure:")
        cursor.execute("PRAGMA table_info(projects)")
        columns = cursor.fetchall()
        for col in columns:
            print(f"   {col[1]} ({col[2]}) - NOT NULL: {bool(col[3])}")
        
        # Check data
        print("\n2. Projects data:")
        cursor.execute("SELECT * FROM projects")
        projects = cursor.fetchall()
        
        if not projects:
            print("   No projects found")
        else:
            for i, project in enumerate(projects):
                print(f"   Project {i+1}: {project}")
        
        # Check specific fields that might be causing issues
        print("\n3. Checking for NULL values in required fields:")
        cursor.execute("""
            SELECT id, name, code_name, client_name, project_type, status, created_at, updated_at
            FROM projects
        """)
        projects = cursor.fetchall()
        
        for project in projects:
            print(f"   ID: {project[0]}")
            print(f"     Name: {project[1]}")
            print(f"     Code: {project[2]}")
            print(f"     Client: {project[3]}")
            print(f"     Type: {project[4]}")
            print(f"     Status: {project[5]}")
            print(f"     Created: {project[6]}")
            print(f"     Updated: {project[7]}")
            print()
        
    except Exception as e:
        print(f"Error: {e}")
    finally:
        if conn:
            conn.close()

if __name__ == "__main__":
    debug_projects()