-- =============================================================================
-- BeKind Backend — Notification Analytics (Future)
-- Table: notification_events
-- Purpose: Track notification events (read, opened, clicked, dismissed) for analytics
-- Depends on: 003-notification-schema.sql (notification_receipts, notification_devices)
--
-- FUTURE: Uncomment and run this migration when implementing notification analytics
-- Note: This table is partitioned by RANGE(created_at)
--       Partitions must be created manually or via scheduled job
-- =============================================================================

-- Notification events table (analytics - read, opened, clicked, dismissed)
-- Append-only for strong analytics
-- Uncomment below when implementing notification analytics

-- CREATE TABLE IF NOT EXISTS notification_events (
--     id         UUID DEFAULT uuid_generate_v4(),
--     receipt_id UUID NOT NULL REFERENCES notification_receipts(id) ON DELETE CASCADE,
--     user_id    UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
--     event_type notification_event_type NOT NULL,
--     device_id  UUID REFERENCES notification_devices(id) ON DELETE SET NULL,
--     metadata   JSONB DEFAULT '{}'::jsonb,
--     created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
--     PRIMARY KEY (id, created_at)
-- ) PARTITION BY RANGE (created_at);

-- =============================================================================
-- INDEXES
-- =============================================================================

-- CREATE INDEX IF NOT EXISTS idx_notification_events_receipt_id
--     ON notification_events(receipt_id);

-- CREATE INDEX IF NOT EXISTS idx_notification_events_user_id
--     ON notification_events(user_id);

-- CREATE INDEX IF NOT EXISTS idx_notification_events_event_type
--     ON notification_events(event_type);

-- CREATE INDEX IF NOT EXISTS idx_notification_events_created_at
--     ON notification_events(created_at DESC);

-- CREATE INDEX IF NOT EXISTS idx_notification_events_user_event_type
--     ON notification_events(user_id, event_type, created_at DESC);
