-- Query to check count of unpaired translations
-- Unpaired translations are translation records that reference text_id values
-- that don't exist in the vgate.text table

-- Count of unpaired translations
SELECT 
    'Unpaired translations count' as description,
    COUNT(*) as count
FROM vgate.translation t
LEFT JOIN vgate.text txt ON t.text_id = txt.id
WHERE txt.id IS NULL;

-- Detailed view of unpaired translations (first 10)
SELECT 
    'Sample unpaired translations' as description,
    t.id as translation_id,
    t.text_id,
    t.language_id,
    t.country_id,
    t.content,
    t.type,
    t.created_at,
    t.updated_at
FROM vgate.translation t
LEFT JOIN vgate.text txt ON t.text_id = txt.id
WHERE txt.id IS NULL
ORDER BY t.created_at DESC
LIMIT 10;

-- Count by language for unpaired translations
SELECT 
    'Unpaired translations by language' as description,
    t.language_id,
    t.country_id,
    COUNT(*) as count
FROM vgate.translation t
LEFT JOIN vgate.text txt ON t.text_id = txt.id
WHERE txt.id IS NULL
GROUP BY t.language_id, t.country_id
ORDER BY count DESC;

-- Count by translation type for unpaired translations
SELECT 
    'Unpaired translations by type' as description,
    t.type,
    COUNT(*) as count
FROM vgate.translation t
LEFT JOIN vgate.text txt ON t.text_id = txt.id
WHERE txt.id IS NULL
GROUP BY t.type
ORDER BY count DESC;

-- Total counts for reference
SELECT 
    'Total translations' as description,
    COUNT(*) as count
FROM vgate.translation;

SELECT 
    'Total text records' as description,
    COUNT(*) as count
FROM vgate.text;
