-- ============================================================
-- Migration: 008_update_notification_settings
-- Date: 2025-01-04
-- Author: Claude
-- Description: Add new notification setting columns for mobile app
-- ============================================================

-- UP: Apply migration
-- ============================================================

-- Add new columns for alert types
ALTER TABLE notification_settings
ADD COLUMN IF NOT EXISTS emergency_alerts BOOLEAN DEFAULT true,
ADD COLUMN IF NOT EXISTS activity_alerts BOOLEAN DEFAULT true,
ADD COLUMN IF NOT EXISTS low_battery BOOLEAN DEFAULT true,
ADD COLUMN IF NOT EXISTS daily_summary BOOLEAN DEFAULT false,
ADD COLUMN IF NOT EXISTS weekly_summary BOOLEAN DEFAULT true;

-- Migrate existing data if needed (optional - map old to new)
UPDATE notification_settings SET
    emergency_alerts = COALESCE(urgent_alerts_enabled, true),
    daily_summary = COALESCE(daily_report_enabled, true),
    weekly_summary = COALESCE(weekly_report_enabled, true)
WHERE emergency_alerts IS NULL;

-- Comments
COMMENT ON COLUMN notification_settings.emergency_alerts IS 'Falls, inactivity, SOS button alerts';
COMMENT ON COLUMN notification_settings.activity_alerts IS 'Unusual activity pattern alerts';
COMMENT ON COLUMN notification_settings.low_battery IS 'Device battery warnings';
COMMENT ON COLUMN notification_settings.daily_summary IS 'Daily wellness report';
COMMENT ON COLUMN notification_settings.weekly_summary IS 'Weekly health digest';

-- ============================================================
-- DOWN: Rollback migration (for reference only)
-- ============================================================
-- ALTER TABLE notification_settings
-- DROP COLUMN IF EXISTS emergency_alerts,
-- DROP COLUMN IF EXISTS activity_alerts,
-- DROP COLUMN IF EXISTS low_battery,
-- DROP COLUMN IF EXISTS daily_summary,
-- DROP COLUMN IF EXISTS weekly_summary;
