{"-- Create notification methods table
CREATE TABLE public.notification_methods (
  id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
  name_ar TEXT NOT NULL,
  name_en TEXT NOT NULL,
  type TEXT NOT NULL CHECK (type IN ('whatsapp', 'email', 'phone', 'sms')),
  icon TEXT DEFAULT 'bell',
  enabled BOOLEAN NOT NULL DEFAULT true,
  settings JSONB DEFAULT '{}',
  created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
  updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
  created_by UUID REFERENCES auth.users(id)
)","-- Enable RLS
ALTER TABLE public.notification_methods ENABLE ROW LEVEL SECURITY","-- Create policies
CREATE POLICY \"Super admin can manage notification methods\" 
ON public.notification_methods 
FOR ALL 
USING (is_current_user_super_admin())","CREATE POLICY \"Users can view notification methods\" 
ON public.notification_methods 
FOR SELECT 
USING (enabled = true)","-- Add user notification preferences to user_roles table
ALTER TABLE public.user_roles 
ADD COLUMN notification_type TEXT CHECK (notification_type IN ('whatsapp', 'email', 'phone', 'sms')),
ADD COLUMN notification_value TEXT","-- Insert default notification methods
INSERT INTO public.notification_methods (name_ar, name_en, type, icon) VALUES
('واتساب', 'WhatsApp', 'whatsapp', 'message-circle'),
('البريد الإلكتروني', 'Email', 'email', 'mail'),
('الهاتف', 'Phone', 'phone', 'phone'),
('الرسائل النصية', 'SMS', 'sms', 'message-square')","-- Create trigger for updated_at
CREATE TRIGGER update_notification_methods_updated_at
BEFORE UPDATE ON public.notification_methods
FOR EACH ROW
EXECUTE FUNCTION public.update_modified_column()"}