-- MobileDukaan Seed Data
-- Run AFTER schema.sql

SET NAMES utf8mb4;

-- Admin user created by install.php (uses ADMIN_EMAIL / ADMIN_PASSWORD from .env)

-- Brands
INSERT INTO brands (name, slug, sort_order) VALUES
('iPhone', 'iphone', 1),
('Samsung', 'samsung', 2),
('OnePlus', 'oneplus', 3),
('Vivo', 'vivo', 4),
('Oppo', 'oppo', 5),
('Xiaomi', 'xiaomi', 6),
('Realme', 'realme', 7),
('Nothing', 'nothing', 8);

-- Phone models
INSERT INTO phone_models (brand_id, name, slug, release_year, sort_order) VALUES
(1, '14 Pro', '14-pro', 2022, 1),
(1, '13', '13', 2021, 2),
(1, '12', '12', 2020, 3),
(2, 'S23 Ultra', 's23-ultra', 2023, 1),
(2, 'Galaxy Z Flip 5', 'z-flip-5', 2023, 2),
(2, 'Galaxy A54', 'a54', 2023, 3),
(3, '11R', '11r', 2023, 1),
(3, '12R', '12r', 2024, 2),
(4, 'V29 Pro', 'v29-pro', 2023, 1),
(5, 'Reno 10 Pro', 'reno-10-pro', 2023, 1),
(6, '13 Pro', '13-pro', 2023, 1);

-- Variants
INSERT INTO model_variants (phone_model_id, name, storage, ram, sort_order) VALUES
(1, '256GB', '256GB', '6GB', 1),
(1, '128GB', '128GB', '6GB', 2),
(2, '128GB', '128GB', '4GB', 1),
(3, '128GB', '128GB', '4GB', 1),
(4, '512GB', '512GB', '12GB', 1),
(5, '256GB', '256GB', '8GB', 1),
(7, '128GB', '128GB', '8GB', 1);

-- Colors
INSERT INTO colors (name, hex_code, sort_order) VALUES
('Black', '#1a1a1a', 1),
('White', '#f5f5f5', 2),
('Deep Purple', '#5e4b8b', 3),
('Midnight', '#1c1c1e', 4),
('Blue', '#2768a8', 5),
('Mint', '#98d8c8', 6),
('Galactic Silver', '#c0c0c0', 7);

-- Cities
INSERT INTO cities (name, state, sort_order) VALUES
('Delhi', 'Delhi', 1),
('Mumbai', 'Maharashtra', 2),
('Bangalore', 'Karnataka', 3),
('Hyderabad', 'Telangana', 4),
('Chennai', 'Tamil Nadu', 5),
('Pune', 'Maharashtra', 6),
('Jaipur', 'Rajasthan', 7),
('Kolkata', 'West Bengal', 8),
('Ahmedabad', 'Gujarat', 9),
('Surat', 'Gujarat', 10);

-- Conditions
INSERT INTO phone_conditions (name, slug, sort_order) VALUES
('Excellent', 'excellent', 1),
('Good', 'good', 2),
('Fair', 'fair', 3),
('Refurbished', 'refurbished', 4);

-- Subscription plans (admin + seller)
INSERT INTO subscription_plans (name, slug, price_monthly, price_yearly, device_limit, features, is_popular, sort_order) VALUES
('Starter', 'starter', 1999.00, 19190.00, 100, '["100 inventory listings","Basic billing & KYC","Shop QR + marketplace listing","WhatsApp broadcasts (500/mo)"]', 0, 1),
('Growth', 'growth', 4999.00, 47990.00, 500, '["Unlimited inventory","AI Instagram automation","Featured marketplace listings","CRM pipelines","WhatsApp broadcasts (5000/mo)","Repair ticketing"]', 1, 2),
('Pro', 'pro', 9999.00, 95990.00, 2000, '["Everything in Growth","Multi-outlet sync","Advanced analytics","Custom branding","Priority support","Dedicated account manager"]', 0, 3);

-- CMS Settings
INSERT INTO cms_settings (page_key, meta_title, meta_description, og_title, og_description) VALUES
('seller_landing', 'MobileDukaan for Sellers — Run Your Entire Mobile Shop From One App', 'India''s first operating system for second-hand mobile phone shops.', 'MobileDukaan — The OS for India''s Mobile Shops', 'Buy phones, manage inventory, generate bills, create Instagram posts, and grow your shop automatically.');

-- CMS Hero
INSERT INTO cms_hero (badge_text, headline, headline_highlight, subheadline, cta_primary_text, cta_primary_url, cta_secondary_text, cta_secondary_url) VALUES
('India''s first second-hand mobile OS', 'Run Your Entire Mobile Shop', 'From One App', 'Buy phones, manage inventory, generate bills, create Instagram posts, track customers, and grow your business automatically.', 'Book a Live Demo', '/auth/register', 'Start Free Trial →', '/auth/register');

-- Ticker
INSERT INTO cms_ticker_items (text, sort_order) VALUES
('Sharma Mobile sold iPhone 14 Pro · ₹64,999', 1),
('Patel Electronics listed Samsung S23 · Mumbai', 2),
('New shop joined from Jaipur · Mobile Hub', 3),
('₹84L+ GMV processed this month on MobileDukaan', 4),
('240+ shops active across 220 cities', 5);

-- Transformation (old way problems)
INSERT INTO cms_transformation_items (tag, title, description, sort_order) VALUES
('01', 'Manual Registers', 'Notebooks, Excel sheets, and memory — one lost page means lost profit.', 1),
('02', 'No Online Presence', 'Customers search OLX before visiting your shop. You''re invisible.', 2),
('03', 'WhatsApp Chaos', '500 unread messages. No idea which customer is hot or cold.', 3),
('04', 'Billing Headaches', 'GST invoices by hand. CA fees every month for basic compliance.', 4),
('05', 'Dead Inventory', 'Phones sitting 90+ days. No alerts, no price drops, no action.', 5),
('06', 'Zero Analytics', 'You don''t know your best-selling brand, profit margin, or lead conversion.', 6);

-- Feature stories
INSERT INTO cms_feature_stories (tag, title, description, link_text, link_url, sort_order) VALUES
('01 · Inventory', 'Every phone. One dashboard.', 'Onboard devices with IMEI, photos, condition & pricing. Track stock value in real time.', 'See inventory →', '/auth/register', 1),
('02 · Marketplace', 'List once. Sell everywhere.', 'Your inventory auto-lists on MobileDukaan buyer portal. WhatsApp leads flow directly to CRM.', 'See marketplace →', '/auth/register', 2),
('03 · Social', 'Instagram on autopilot.', 'AI generates posts, stories & WhatsApp statuses from your live inventory. One click to publish.', 'See social →', '/auth/register', 3);

-- Marketplace section
INSERT INTO cms_marketplace (headline, subheadline, stat_value, stat_label, cta_text, cta_url) VALUES
('Your shop on India''s largest used-phone network.', 'Buyers in 220+ cities discover your inventory. Verified listings, transparent pricing, direct WhatsApp contact.', '4,209', 'listings active in 220+ cities', 'List Your Shop →', '/auth/register');

-- Analytics
INSERT INTO cms_analytics_banner (section_title, section_highlight, network_gmv_label, network_gmv_value) VALUES
('Numbers, finally', 'on your side.', 'Total Network GMV · this month', '₹84,21,500');

INSERT INTO cms_analytics_kpis (label, value, trend, progress_width, sort_order) VALUES
('Stock Value', '₹85.4L', '+12.4%', '75%', 1),
('Monthly Profit', '₹6.2L', '+24%', '68%', 2),
('Phones Sold', '184', '+18', '55%', 3),
('Lead Conversion', '68%', '+9pp', '68%', 4),
('Dead Inventory', '−14%', 'Improving', '82%', 5),
('Customer Retention', '42%', '+6pp', '42%', 6);

-- Ecosystem nodes
INSERT INTO cms_ecosystem_nodes (name, sort_order) VALUES
('Inventory', 1), ('Marketplace', 2), ('Billing', 3), ('Instagram', 4),
('CRM', 5), ('WhatsApp', 6), ('Repairs', 7), ('Payments', 8);

-- Testimonials
INSERT INTO cms_testimonials (name, shop_label, quote, before_value, after_value, sort_order) VALUES
('Imran Sheikh', 'Sheikh Mobile · Hyderabad', 'Pehle din mein 4 ghante notebook mein time waste hota tha. Ab WhatsApp pe customer ka reply 30 second mein jaata hai.', '₹2.4L /mo', '₹6.8L /mo', 1),
('Priya Nair', 'Nair Telecom · Kochi', 'Instagram automation alone brought 240 new customers in 60 days. The AI knows what looks good.', '120 followers', '8.4k followers', 2),
('Sureshbhai Patel', 'Patel Electronics · Surat', 'Repair tracking ne meri service shop bachayi. Ab koi device kho nahin sakta.', '32% retention', '71% retention', 3);

-- CMS Pricing (display plans - can sync with subscription_plans)
INSERT INTO cms_pricing_plans (name, price_display, price_monthly, description, cta_text, cta_url, is_featured, sort_order) VALUES
('Starter', '₹1,999', 1999, 'For new shops finding their feet.', 'Get Started', '/auth/register', 0, 1),
('Growth', '₹4,999', 4999, 'Most popular for thriving shops.', 'Start Free Trial', '/auth/register', 1, 2),
('Pro', '₹9,999', 9999, 'Multi-outlet chains and power-sellers.', 'Contact Sales', '/auth/register', 0, 3);

INSERT INTO cms_pricing_features (plan_id, feature_text, sort_order) VALUES
(1, '100 inventory listings', 1), (1, 'Basic billing & KYC', 2), (1, 'Shop QR + marketplace listing', 3), (1, 'WhatsApp broadcasts (500/mo)', 4),
(2, 'Unlimited inventory', 1), (2, 'AI Instagram automation', 2), (2, 'Featured marketplace listings', 3), (2, 'CRM pipelines & follow-ups', 4), (2, 'WhatsApp broadcasts (5,000/mo)', 5), (2, 'Repair ticketing', 6),
(3, 'Everything in Growth', 1), (3, 'Multi-outlet sync', 2), (3, 'Advanced analytics & reports', 3), (3, 'Custom branding on invoices', 4), (3, 'Priority WhatsApp support', 5), (3, 'Dedicated account manager', 6);

-- Final CTA
INSERT INTO cms_final_cta (headline, headline_highlight, subheadline, cta_text, cta_url) VALUES
('Your mobile shop deserves better tools.', 'Start today.', 'Join 1,200+ shops already running on MobileDukaan. 14-day free trial, no credit card.', 'Start Free Trial →', '/auth/register');

-- Stats
INSERT INTO cms_stats (value, label, sort_order) VALUES
('1,200+', 'Active Shops', 1), ('220+', 'Cities', 2), ('₹84L+', 'Monthly GMV', 3), ('4.9★', 'Avg Rating', 4);

-- Nav links
INSERT INTO cms_nav_links (label, url, location, sort_order) VALUES
('Platform', '#platform', 'header', 1), ('For Buyers', '/', 'header', 2), ('Browse Phones', '/browse', 'header', 3), ('Analytics', '#analytics', 'header', 4), ('Pricing', '#pricing', 'header', 5),
('Privacy', '#', 'footer', 1), ('Terms', '#', 'footer', 2), ('Support', '#', 'footer', 3);

-- Floating cards
INSERT INTO cms_floating_cards (card_type, title, subtitle, body_text, value_display, trend_text, position, sort_order) VALUES
('whatsapp', 'WhatsApp Inquiry', 'Rohit Sharma · just now', 'Bhai, iPhone 13 128GB available hai? Price kya hogi?', NULL, NULL, 'left', 1),
('revenue', 'Daily Revenue', NULL, NULL, '₹1,42,800', '▲ 24% vs last week', 'right', 2),
('instagram', '@yourshop · Story posted', NULL, NULL, NULL, NULL, 'right', 3);

-- Platform settings
INSERT INTO platform_settings (setting_key, setting_value, setting_type) VALUES
('platform_name', 'MobileDukaan', 'string'),
('support_email', 'support@mobiledukaan.in', 'string'),
('trial_days', '14', 'number'),
('auto_approve_listings', 'false', 'boolean'),
('max_listings_per_shop', '50', 'number'),
('maintenance_mode', 'false', 'boolean'),
('buyer_portal_enabled', 'true', 'boolean'),
('whatsapp_integration', 'true', 'boolean');

-- Sample shops
INSERT INTO shops (name, slug, owner_name, email, phone, gstin, address, city_name, plan_id, status, verified, whatsapp_enabled, devices_count, portal_listings_count, total_sales, revenue, mrr, employees_count, subscription_ends_at, joined_at) VALUES
('Sharma Mobile Centre', 'sharma-mobile-centre', 'Rohan Sharma', 'rohan@sharmamobile.in', '+91 98765 43210', '07AABCS1429B1Z5', 'Shop 12, Nehru Place, Delhi', 'Delhi', 2, 'active', 1, 1, 47, 4, 312, 892400, 4999, 4, '2026-08-15', '2025-08-15'),
('Patel Electronics', 'patel-electronics', 'Jay Patel', 'jay@patelelectronics.in', '+91 98200 11223', '27AABCP2345C1Z8', 'Lamington Road, Mumbai', 'Mumbai', 3, 'active', 1, 1, 68, 3, 489, 1240000, 9999, 8, '2026-06-20', '2025-06-20'),
('Mobile Hub Jaipur', 'mobile-hub-jaipur', 'Anita Singh', 'anita@mobilehub.in', '+91 94140 55667', '08AABCM3456D1Z2', 'MI Road, Jaipur', 'Jaipur', 1, 'trial', 0, 0, 12, 2, 18, 124000, 0, 2, '2026-07-01', '2026-06-01'),
('Tech Point Bangalore', 'tech-point-bangalore', 'Karthik R', 'karthik@techpoint.in', '+91 99800 77889', '29AABCT4567E1Z4', 'SP Road, Bangalore', 'Bangalore', 2, 'active', 1, 1, 52, 2, 267, 980000, 4999, 5, '2026-11-10', '2025-11-10'),
('City Mobile Chennai', 'city-mobile-chennai', 'Lakshmi N', 'lakshmi@citymobile.in', '+91 98400 99001', '33AABCC5678F1Z6', 'T Nagar, Chennai', 'Chennai', 3, 'suspended', 1, 0, 0, 0, 156, 0, 0, 0, '2026-03-05', '2025-03-05');

-- Verification requests
INSERT INTO verification_requests (shop_id, request_type, status, notes, documents) VALUES
(3, 'shop_verification', 'pending', NULL, '[{"name":"GST Certificate","type":"pdf"},{"name":"Shop Photo","type":"image"}]'),
(1, 'listing_review', 'pending', 'High-value listing requires manual review', '[{"name":"iPhone 12 Bill","type":"pdf"}]');

-- Support tickets
INSERT INTO support_tickets (ticket_code, shop_id, subject, description, priority, status, assigned_to) VALUES
('TK-001', 2, 'GST invoice format issue', 'GST invoices are not showing HSN codes correctly for repair services.', 'high', 'open', 'Unassigned'),
('TK-002', 3, 'Need help with onboarding', 'New shop owner struggling with phone onboarding flow.', 'medium', 'in_progress', 'Neha Support');

INSERT INTO support_messages (ticket_id, sender_name, message) VALUES
(1, 'Jay Patel', 'Our CA flagged missing HSN codes on repair invoices.'),
(1, 'Support', 'We are investigating the invoice template. Will update within 24h.'),
(2, 'Anita Singh', 'How do I list phones on the buyer portal?'),
(2, 'Neha Support', 'I will schedule a 30-min onboarding call for tomorrow.');

-- Portal listings
INSERT INTO portal_listings (shop_id, title, brand_name, price, status, flags, views) VALUES
(1, 'iPhone 14 Pro 256GB', 'iPhone', 64999, 'approved', '[]', 342),
(1, 'iPhone 12 128GB', 'iPhone', 27999, 'pending', '["high_value"]', 0),
(3, 'Oppo Reno 10 Pro', 'Oppo', 22999, 'flagged', '["no_bill","low_battery"]', 12);

-- Platform users (buyers - admin managed for now)
INSERT INTO platform_users (name, email, phone, city_name, purchases, total_spent, inquiries, status, joined_at) VALUES
('Rahul Mehta', 'rahul.m@email.com', '+91 98100 11111', 'Delhi', 2, 89000, 14, 'active', '2025-12-01'),
('Priya Kapoor', 'priya.k@email.com', '+91 98200 22222', 'Mumbai', 1, 39999, 8, 'active', '2026-01-15'),
('Vikram Joshi', 'vikram.j@email.com', '+91 98700 77777', 'Jaipur', 0, 0, 45, 'blocked', '2026-04-01');

-- Admin alerts
INSERT INTO admin_alerts (type, title, message, is_read) VALUES
('critical', 'Payment failure spike', '12 shops failed subscription renewal in last 24h', 0),
('warning', 'Verification backlog', '5 shop verifications pending review for 48+ hours', 0),
('info', 'New trial signups', '8 new shops started trial today', 1),
('success', 'MRR milestone', 'Platform MRR crossed ₹28.4L this month', 1);

-- Revenue snapshots
INSERT INTO revenue_snapshots (month_key, mrr, arr, new_shops, churned_shops) VALUES
('2026-01', 2100000, 25200000, 42, 8),
('2026-02', 2280000, 27360000, 48, 6),
('2026-03', 2450000, 29400000, 55, 10),
('2026-04', 2580000, 30960000, 51, 7),
('2026-05', 2720000, 32640000, 62, 9),
('2026-06', 2840000, 34080000, 38, 5);

-- Activity logs
INSERT INTO admin_activity_logs (actor, action, target, category, ip_address) VALUES
('Super Admin', 'Approved shop verification', 'Mobile Hub Jaipur', 'shop', '103.21.45.88'),
('System', 'Subscription renewed', 'Patel Electronics — Pro', 'billing', 'system'),
('Super Admin', 'Suspended shop account', 'City Mobile Chennai', 'shop', '103.21.45.88');
