-- Test Asset Ownership Storage
-- This SQL script verifies that ownership_type is being stored correctly

-- 1. Check recent assets and their ownership_type
SELECT 
    id,
    type,
    description,
    value,
    ownership_type,
    ownership_percentage,
    category,
    source,
    created_at
FROM assets
ORDER BY created_at DESC
LIMIT 10;

-- 2. Count assets by ownership_type
SELECT 
    COALESCE(ownership_type, 'NULL/EMPTY') as ownership_type,
    COUNT(*) as count,
    AVG(ownership_percentage) as avg_percentage
FROM assets
GROUP BY ownership_type
ORDER BY count DESC;

-- 3. Check for assets with NULL or empty ownership_type (bug indicator)
SELECT COUNT(*) as null_ownership_count
FROM assets
WHERE ownership_type IS NULL OR ownership_type = '';

-- 4. Check recent assets from lawyer_onboarding source
SELECT 
    id,
    type,
    description,
    value,
    ownership_type,
    ownership_percentage,
    source,
    created_at
FROM assets
WHERE source = 'lawyer_onboarding'
ORDER BY created_at DESC
LIMIT 5;

-- 5. Verify the assets table structure
DESCRIBE assets;
