-- View joining case_hours to cases for client context
CREATE OR REPLACE VIEW case_hour_details AS
SELECT h.*, c.client_id
FROM case_hours h
LEFT JOIN cases c ON h.case_id = c.id;

-- Register view for sync
INSERT INTO tenant_tables (tenant_id, user_id, table_name, definition)
SELECT NULL, NULL, 'case_hour_details', '{}'
WHERE NOT EXISTS (SELECT 1 FROM tenant_tables WHERE table_name = 'case_hour_details');
