-- ============================================================================
-- VERIFY COMPANY DATA - Check what records exist for a company
-- ============================================================================

DECLARE @CompanyId INT = 1; -- Demo Company

PRINT '============================================================================';
PRINT 'DATA VERIFICATION - Company ID: ' + CAST(@CompanyId AS NVARCHAR(10));
PRINT '============================================================================';
PRINT '';

-- Lookup Tables
PRINT 'LOOKUP TABLES:';
SELECT 'JobStatusLookup' AS TableName, COUNT(*) AS TotalRows, SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END) AS SoftDeleted
FROM JobStatusLookups WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'JobPriorityLookup', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM JobPriorityLookups WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'QuoteStatusLookup', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM QuoteStatusLookups WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'InventoryCategoryLookup', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM InventoryCategoryLookups WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'AppointmentStatusLookup', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM AppointmentStatusLookups WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'AppointmentTypeLookup', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM AppointmentTypeLookups WHERE CompanyId = @CompanyId;

PRINT '';
PRINT 'BASE ENTITIES:';
SELECT 'Customers' AS TableName, COUNT(*) AS TotalRows, SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END) AS SoftDeleted
FROM Customers WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'InventoryItems', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM InventoryItems WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'Equipment', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM Equipment WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'PricingTiers', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM PricingTiers WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'CompanyOperatingCosts', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM CompanyOperatingCosts WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'CatalogCategories', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM CatalogCategories WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'CatalogItems', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM CatalogItems WHERE CompanyId = @CompanyId;

PRINT '';
PRINT 'TRANSACTIONAL DATA:';
SELECT 'Quotes' AS TableName, COUNT(*) AS TotalRows, SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END) AS SoftDeleted
FROM Quotes WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'Jobs', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM Jobs WHERE CompanyId = @CompanyId
UNION ALL
SELECT 'Appointments', COUNT(*), SUM(CASE WHEN IsDeleted = 1 THEN 1 ELSE 0 END)
FROM Appointments WHERE CompanyId = @CompanyId;

PRINT '';
PRINT '============================================================================';
PRINT 'If TotalRows > 0, the hard delete did not work correctly!';
PRINT 'If SoftDeleted > 0, there are soft-deleted records blocking seeding!';
PRINT '============================================================================';
