-- ============================================================
-- Migration: 004_create_notification_settings
-- Date: 2025-12-19
-- Author: Claude
-- Description: Create table for user notification preferences
-- ============================================================

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

CREATE TABLE IF NOT EXISTS notification_settings (
    user_id INTEGER PRIMARY KEY REFERENCES person_details(user_id) ON DELETE CASCADE,

    -- Alert preferences
    alerts_enabled BOOLEAN DEFAULT true,
    urgent_alerts_enabled BOOLEAN DEFAULT true,
    daily_report_enabled BOOLEAN DEFAULT true,
    weekly_report_enabled BOOLEAN DEFAULT true,

    -- Quiet hours
    quiet_hours_enabled BOOLEAN DEFAULT false,
    quiet_hours_start TIME DEFAULT '22:00',
    quiet_hours_end TIME DEFAULT '07:00',

    -- Channel preferences
    push_enabled BOOLEAN DEFAULT true,
    email_enabled BOOLEAN DEFAULT true,
    sms_enabled BOOLEAN DEFAULT false,

    -- Timestamps
    created_at TIMESTAMPTZ DEFAULT NOW(),
    updated_at TIMESTAMPTZ DEFAULT NOW()
);

-- Comments
COMMENT ON TABLE notification_settings IS 'Per-user notification preferences';
COMMENT ON COLUMN notification_settings.quiet_hours_enabled IS 'Mute non-urgent notifications during quiet hours';
COMMENT ON COLUMN notification_settings.urgent_alerts_enabled IS 'Urgent alerts (no activity 6+ hours) bypass quiet hours';

-- ============================================================
-- DOWN: Rollback migration (for reference only)
-- ============================================================
-- DROP TABLE IF EXISTS notification_settings;
