-- Default Seed Data for WhatsApp CRM

-- 1. Default Admin User
-- Email: admin@crm.local
-- Password: password123 (Hash generated with password_hash('password123', PASSWORD_BCRYPT))
INSERT INTO `users` (`id`, `name`, `email`, `password_hash`, `role`, `status`, `phone`) VALUES
(1, 'System Administrator', 'admin@crm.local', '$2y$10$YTGvh70zNsmDkWU4h94i4u3M7wQJq9JqD0mZ9xR2fL6U8eE5yO2wG', 'admin', 'active', '+1234567890'),
(2, 'Sarah Jenkins', 'sarah@crm.local', '$2y$10$YTGvh70zNsmDkWU4h94i4u3M7wQJq9JqD0mZ9xR2fL6U8eE5yO2wG', 'agent', 'active', '+1234567891');

-- 2. Default Pipeline Stages
INSERT INTO `pipeline_stages` (`id`, `name`, `color`, `order_index`) VALUES
(1, 'New Lead', '#3b82f6', 1),
(2, 'Contacted', '#8b5cf6', 2),
(3, 'Qualified', '#f59e0b', 3),
(4, 'Proposal Sent', '#06b6d4', 4),
(5, 'Closed Won', '#10b981', 5),
(6, 'Closed Lost', '#ef4444', 6);

-- 3. Default Tags
INSERT INTO `tags` (`id`, `name`, `color`) VALUES
(1, 'Hot Lead', '#ef4444'),
(2, 'VIP Customer', '#8b5cf6'),
(3, 'Demo Scheduled', '#3b82f6'),
(4, 'Support Needed', '#f59e0b'),
(5, 'Cold Lead', '#64748b');

-- 4. Sample Contacts
INSERT INTO `contacts` (`id`, `whatsapp_id`, `phone_number`, `name`, `email`, `company`, `stage_id`, `assigned_to`, `notes`) VALUES
(1, '15550192834', '+15550192834', 'Alex Reynolds', 'alex@techcorp.com', 'TechCorp Solutions', 1, 1, 'Interested in Enterprise WhatsApp CRM licensing.'),
(2, '15550293845', '+15550293845', 'Elena Rostova', 'elena@luxgoods.io', 'LuxGoods Retail', 2, 2, 'Requested a pricing breakdown for 10 agent seats.'),
(3, '15550394856', '+15550394856', 'David Kim', 'david@growthex.co', 'GrowthEx Agency', 4, 1, 'Proposal sent on Monday. Follow up by Thursday.');

-- 5. Contact Tags
INSERT INTO `contact_tags` (`contact_id`, `tag_id`) VALUES
(1, 1),
(1, 3),
(2, 2),
(3, 1);

-- 6. Sample Deals
INSERT INTO `deals` (`id`, `contact_id`, `stage_id`, `title`, `value`, `currency`, `closing_date`, `assigned_to`, `notes`, `status`) VALUES
(1, 1, 1, 'TechCorp Enterprise Plan', 4500.00, 'USD', DATE_ADD(CURRENT_DATE, INTERVAL 14 DAY), 1, '50 seats with automated broadcasts.', 'open'),
(2, 2, 2, 'LuxGoods 10-Seat CRM Setup', 1800.00, 'USD', DATE_ADD(CURRENT_DATE, INTERVAL 7 DAY), 2, 'Needs catalog integration.', 'open'),
(3, 3, 4, 'GrowthEx Annual License', 6200.00, 'USD', DATE_ADD(CURRENT_DATE, INTERVAL 3 DAY), 1, 'Awaiting approval from procurement.', 'open');

-- 7. Sample Conversations & Messages
INSERT INTO `conversations` (`id`, `contact_id`, `assigned_user_id`, `status`, `unread_count`, `last_message`, `last_message_at`) VALUES
(1, 1, 1, 'open', 1, 'Hi, does your WhatsApp CRM support multiple agent logins?', NOW()),
(2, 2, 2, 'open', 0, 'We have received your proposal, thank you!', DATE_SUB(NOW(), INTERVAL 2 HOUR)),
(3, 3, 1, 'open', 0, 'Can we schedule a quick demo on Zoom?', DATE_SUB(NOW(), INTERVAL 1 DAY));

INSERT INTO `messages` (`id`, `conversation_id`, `contact_id`, `user_id`, `direction`, `message_type`, `content`, `status`, `created_at`) VALUES
(1, 1, 1, NULL, 'inbound', 'text', 'Hello there! I found your website online.', 'read', DATE_SUB(NOW(), INTERVAL 30 MINUTE)),
(2, 1, 1, 1, 'outbound', 'text', 'Hi Alex! Welcome to our WhatsApp CRM. How can we help you today?', 'read', DATE_SUB(NOW(), INTERVAL 25 MINUTE)),
(3, 1, 1, NULL, 'inbound', 'text', 'Hi, does your WhatsApp CRM support multiple agent logins?', 'delivered', NOW()),

(4, 2, 2, NULL, 'inbound', 'text', 'Good afternoon! Could you please share the pricing sheet?', 'read', DATE_SUB(NOW(), INTERVAL 3 HOUR)),
(5, 2, 2, 2, 'outbound', 'text', 'Hello Elena! Absolutely, here is our complete feature matrix and pricing details.', 'read', DATE_SUB(NOW(), INTERVAL 2 HOUR)),
(6, 2, 2, NULL, 'inbound', 'text', 'We have received your proposal, thank you!', 'read', DATE_SUB(NOW(), INTERVAL 2 HOUR));

-- 8. Quick Replies
INSERT INTO `quick_replies` (`id`, `shortcut`, `title`, `message`) VALUES
(1, '/welcome', 'Welcome Greeting', 'Hello {{name}}! Welcome to our customer support. How can our team assist you today?'),
(2, '/pricing', 'Pricing & Plans', 'Thank you for your interest! You can review all our subscription tiers and features here: https://example.com/pricing'),
(3, '/demo', 'Book Demo Call', 'We would love to give you a live tour! Please pick a convenient time on our calendar: https://calendly.com/crm-demo'),
(4, '/support', 'Support Ticket', 'Your request has been logged with ticket ID #{{ticket_id}}. An agent will attend to you shortly.'),
(5, '/thanks', 'Thank You Closing', 'Thank you for chatting with us today! If you have any further questions, feel free to reply anytime. Have a great day!');

-- 9. WhatsApp Templates
INSERT INTO `whatsapp_templates` (`id`, `name`, `category`, `language`, `header_type`, `body_text`, `footer_text`, `status`) VALUES
(1, 'crm_welcome_greeting', 'MARKETING', 'en_US', 'NONE', 'Hi {{1}}, thanks for reaching out to us! Our team has received your message and will get back to you shortly.', 'WhatsApp CRM Bot', 'APPROVED'),
(2, 'lead_followup_reminder', 'UTILITY', 'en_US', 'TEXT', 'Hello {{1}}, just following up on our previous conversation regarding {{2}}. Let us know if you need any additional info!', 'Sales Team', 'APPROVED'),
(3, 'payment_invoice_alert', 'UTILITY', 'en_US', 'DOCUMENT', 'Dear {{1}}, your invoice #{{2}} of {{3}} is ready for review. Please find the attached document.', 'Finance Department', 'APPROVED');

-- 10. Automation Rules
INSERT INTO `automation_rules` (`id`, `name`, `trigger_event`, `trigger_keyword`, `reply_type`, `reply_content`, `action_type`, `action_value`, `is_active`) VALUES
(1, 'Auto Welcome for New Leads', 'welcome_new_contact', NULL, 'text', '👋 Welcome to our CRM! How can we assist you with our products today?', 'add_tag', '1', 1),
(2, 'Keyword Pricing Response', 'message_contains', 'price,pricing,cost,quote', 'text', '💰 You can find our complete price list and plans at https://example.com/pricing or type "demo" to speak with a representative.', 'move_stage', '2', 1),
(3, 'Keyword Demo Booking', 'message_contains', 'demo,schedule,meeting,call', 'text', '📅 Great! You can instantly book a 15-minute live demo here: https://calendly.com/crm-demo', 'add_tag', '3', 1);

-- 11. Settings (WhatsApp Driver, QR Gateway, Meta API, Business Profile, Simulator)
INSERT INTO `settings` (`key`, `value`, `group`) VALUES
('app_name', 'WhatsApp CRM Enterprise', 'general'),
('company_name', 'Acme Global CRM', 'general'),
('timezone', 'Asia/Kolkata', 'general'),
('currency_symbol', '$', 'general'),
('whatsapp_driver', 'gateway', 'whatsapp'),
('gateway_instance_id', 'instance105820', 'gateway'),
('gateway_token', 'your_ultramsg_token_here', 'gateway'),
('gateway_api_url', 'https://api.ultramsg.com', 'gateway'),
('whatsapp_phone_number_id', '100609349424840', 'meta'),
('whatsapp_waba_id', '105829482910482', 'meta'),
('whatsapp_access_token', 'EAAxxxxxxx_PLACEHOLDER_TOKEN', 'meta'),
('whatsapp_verify_token', 'whatsapp_crm_secure_token_2026', 'meta'),
('whatsapp_app_secret', 'abcdef1234567890abcdef1234567890', 'meta'),
('whatsapp_api_version', 'v19.0', 'meta'),
('webhook_simulator_enabled', '1', 'general'),
('working_hours_enabled', '0', 'automation'),
('working_hours_start', '09:00', 'automation'),
('working_hours_end', '18:00', 'automation'),
('out_of_office_reply', 'Thank you for contacting us! Our office is currently closed. We will respond as soon as we open tomorrow at 9:00 AM.', 'automation');
