<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\BlogCategory;
use App\Models\BlogPost;
use App\Models\Faq;
use App\Models\SeoMeta;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Support\Str;

class CMSSeeder extends Seeder
{
    public function run(): void
    {
        $admin = User::where('role', 'super_admin')->first();

        // 1. Blog Categories & Posts
        $categoryGuide = BlogCategory::updateOrCreate(
            ['slug' => 'japan-auction-guides'],
            ['name' => 'Japan Auction Guides', 'description' => 'Expert guides on Japanese car auctions, bidding strategies, and auction sheet verification.']
        );

        $categoryMarket = BlogCategory::updateOrCreate(
            ['slug' => 'bangladesh-auto-market'],
            ['name' => 'Bangladesh Auto Market', 'description' => 'NBR customs rules, tax assessments, duty breakdowns, and landed cost trends.']
        );

        $posts = [
            [
                'blog_category_id' => $categoryGuide->id,
                'title' => 'How to Read a Japanese Auction Sheet: Grades, Condition Maps & Marks Explained',
                'slug' => 'how-to-read-japanese-auction-sheet-grades-condition-map',
                'excerpt' => 'Decode Japanese auction inspection sheets like a pro. Understand overall grades S, 6, 5, 4.5, 4, 3.5, R, and condition codes A1-A3, U1-U3, W1-W3.',
                'content' => "<h3>Understanding Japanese Automobile Auction Inspection Sheets</h3><p>When purchasing a reconditioned vehicle from Japan, the auction sheet is your single most important document. Japanese auction houses (such as USS, TAA, CAA, HAA, and ARAI) employ neutral, certified third-party inspectors who rigorously examine every vehicle before it goes on the auction block.</p><h4>Auction Overall Grades</h4><ul><li><strong>Grade S / 6:</strong> As good as brand new. Less than 12 months old and minimal mileage (under 5,000 km).</li><li><strong>Grade 5.0:</strong> Exceptional condition. Extremely low mileage (under 25,000 km) with virtually unnoticeable wear.</li><li><strong>Grade 4.5:</strong> Very clean, well-maintained vehicle with light wear consistent with age. This is MotoSolution's standard benchmark grade.</li><li><strong>Grade 4.0:</strong> Good condition with minor cosmetic blemishes, scratches, or small dents. Highly recommended for budget-conscious buyers.</li><li><strong>Grade 3.5:</strong> High mileage or noticeable cosmetic wear requiring paint touch-ups.</li><li><strong>Grade R / RA:</strong> Accident history repaired or replacement parts installed. MotoSolution maintains strict quality control and does not source compromised vehicles.</li></ul><h4>Inspection Body Diagram Notation</h4><p>The car schematic map on the auction sheet indicates specific panel conditions:</p><ul><li><strong>A (Scratch):</strong> A1 = Light scratch (buffable), A2 = Medium scratch, A3 = Deep scratch requiring repaint.</li><li><strong>U (Dent):</strong> U1 = Pinpoint dimple, U2 = Noticeable dent, U3 = Large dent requiring panel beating.</li><li><strong>W (Repair / Wave):</strong> W1 = Invisible professional repaint, W2 = Noticeable repair, W3 = Poor repaint.</li><li><strong>XX:</strong> Panel was replaced.</li></ul><p>At MotoSolution Bangladesh, our team in Tokyo physically re-inspects auction lots and translates the handwritten inspector comments into English and Bengali before placing your authorized bid.</p>",
                'featured_image' => 'https://images.unsplash.com/photo-1586281380349-632531db7ed4?w=1200&q=80',
                'meta_title' => 'How to Read Japanese Auction Sheets – Grade 4.5, 5 & Condition Codes | MotoSolution',
                'meta_description' => 'Complete guide on how to verify Japanese car auction sheets. Learn the meaning of Grades S, 5, 4.5, 4, condition marks A1, U1, W1, and inspect genuine sheets.',
            ],
            [
                'blog_category_id' => $categoryMarket->id,
                'title' => 'Bangladesh Car Import Duty 2024-2026: Landed Cost Calculation Breakdown',
                'slug' => 'bangladesh-car-import-duty-landed-cost-calculation-guide',
                'excerpt' => 'A comprehensive guide explaining how customs duty, supplementary duty (SD), VAT, AIT, and regulatory duty are calculated for reconditioned cars entering Chittagong Port.',
                'content' => "<h3>Demystifying Bangladesh Automotive Customs Assessment</h3><p>Importing a Japanese reconditioned vehicle into Bangladesh involves multiple statutory government tariffs determined by the National Board of Revenue (NBR). Knowing how these charges are assessed enables buyers to make smart financial decisions before bidding.</p><h4>1. Assessable Value (AV) and Depreciation</h4><p>Customs calculates Assessable Value based on the vehicle's CIF (Cost, Insurance, and Freight) value in foreign currency converted to Bangladeshi Taka (BDT). NBR allows progressive depreciation based on vehicle age:</p><ul><li>1 year old: 10% depreciation deduction</li><li>2 years old: 20% depreciation deduction</li><li>3 years old: 30% depreciation deduction</li><li>4 to 5 years old: 40% maximum allowable depreciation deduction</li></ul><h4>2. The Duty Structure</h4><p>The total tax incidence (TTI) consists of:</p><ul><li><strong>Customs Duty (CD):</strong> 25% on Assessable Value.</li><li><strong>Regulatory Duty (RD):</strong> 3% on Assessable Value.</li><li><strong>Supplementary Duty (SD):</strong> Ranges from 0% (micro cars) to 20% (1500cc), 45-60% (1800cc), 100% (2000cc), up to 350-500% (3000cc+). Hybrid vehicles enjoy significantly reduced SD rates!</li><li><strong>Value Added Tax (VAT):</strong> 15% on the cumulative base.</li><li><strong>Advance Income Tax (AIT):</strong> 5% on Assessable Value.</li><li><strong>Advance Tax (AT):</strong> 5% on cumulative base.</li></ul><h4>3. The MotoSolution Guarantee</h4><p>Unlike third-party brokers who offer vague estimates, MotoSolution provides a transparent, itemized landed cost statement before you commit to any bid.</p>",
                'featured_image' => 'https://images.unsplash.com/photo-1549399542-7e3f8b79c341?w=1200&q=80',
                'meta_title' => 'Bangladesh Car Import Duty & Landed Cost Breakdown | MotoSolution Guide',
                'meta_description' => 'Understand how Bangladesh customs duty, SD, VAT, and AIT are calculated on Japanese cars imported through Chittagong Port.',
            ],
            [
                'blog_category_id' => $categoryGuide->id,
                'title' => 'Why Toyota Hybrid Vehicles (Harrier, Corolla Cross, Noah) Dominate Bangladesh Roads',
                'slug' => 'why-toyota-hybrids-dominate-bangladesh-roads',
                'excerpt' => 'Exploring how Toyota Synergy Drive hybrid models provide high fuel economy (18-24 km/L), lower customs duty brackets, and exceptional resale value in Dhaka.',
                'content' => "<h3>The Rise of Japanese Hybrid Technology in Bangladesh</h3><p>Over the last decade, Japanese hybrid vehicles have become the preferred choice for discerning car owners in Dhaka and Chittagong. With rising fuel prices and heavy urban traffic, Toyota's self-charging hybrid system offers unmatched practicality.</p><h4>Key Advantages:</h4><ul><li><strong>Fuel Efficiency in Stop-and-Go Traffic:</strong> In Dhaka traffic jams, hybrid engines shut down combustion and operate silently on electric battery power, slashing fuel expenses by 40-50%.</li><li><strong>Lower Government Duty:</strong> Under Bangladesh NBR regulations, hybrid vehicles in the 1500cc-1800cc and 1800cc-2000cc categories benefit from reduced supplementary duty compared to their purely gasoline counterparts.</li><li><strong>Long-Term Durability:</strong> Toyota's nickel-metal hydride and lithium-ion batteries are engineered for the vehicle's lifespan, with local specialized maintenance readily available.</li></ul>",
                'featured_image' => 'https://images.unsplash.com/photo-1590362891988-f778047831d0?w=1200&q=80',
                'meta_title' => 'Why Toyota Hybrids Dominate Bangladesh Roads | MotoSolution Insights',
                'meta_description' => 'Discover the fuel savings, tax benefits, and performance advantages of Toyota Harrier, Corolla Cross, and Noah hybrids in Bangladesh.',
            ],
        ];

        foreach ($posts as $p) {
            BlogPost::updateOrCreate(
                ['slug' => $p['slug']],
                array_merge($p, [
                    'author_id' => $admin?->id,
                    'is_published' => true,
                    'published_at' => now()->subDays(rand(2, 30)),
                    'views_count' => rand(150, 850),
                ])
            );
        }

        // 2. FAQs
        $faqs = [
            [
                'category' => 'General',
                'question' => 'What is MotoSolution and where is your showroom located?',
                'answer' => 'MotoSolution is a premier Japanese reconditioned car importer and pre-order platform in Bangladesh, established in 2016. Our physical showroom and executive sales office are located at House 24, Road 3, Block B, Niketan, Gulshan-1, Dhaka 1212. We have successfully delivered over 700+ verified vehicles to clients across Bangladesh.',
                'sort_order' => 1,
            ],
            [
                'category' => 'General',
                'question' => 'Can I physically inspect cars before buying?',
                'answer' => 'Yes! You can visit our Niketan, Gulshan showroom from Saturday to Thursday (10:00 AM - 8:00 PM) to inspect our Ready Stock inventory and take a test drive. For Japan Auction Pre-orders, we provide original high-resolution auction sheets, 30+ HD photos, video walkarounds, and Japanese inspector notes before bidding.',
                'sort_order' => 2,
            ],
            [
                'category' => 'Auction Bidding',
                'question' => 'Does clicking "Bid Now" automatically buy the car in Japan?',
                'answer' => 'No. When you submit a bid on MotoSolution, you are authorizing your maximum bidding ceiling (in JPY) with its estimated Bangladesh landed cost. The bid enters our system as "Pending" and is reviewed by our auction management team. We confirm the auction sheet and booking details with you before submitting the authorized bid onto the live Japanese auction floor.',
                'sort_order' => 3,
            ],
            [
                'category' => 'Auction Bidding',
                'question' => 'What happens if the car sells for less than my maximum bid in Japan?',
                'answer' => 'You only pay the actual winning hammer price! For example, if you authorized a maximum bid of ¥2,500,000 but MotoSolution secures the car on the floor for ¥2,200,000, your final invoice and Bangladesh customs assessment are adjusted downward accordingly. We practice 100% price transparency.',
                'sort_order' => 4,
            ],
            [
                'category' => 'Customs & Landed Cost',
                'question' => 'How accurate is the Bangladesh Landed Cost Calculator on the website?',
                'answer' => 'Our landed cost calculator utilizes the official Bangladesh National Board of Revenue (NBR) customs tariff schedules, including Engine CC brackets, hybrid duty concessions, vehicle age depreciation, CIF shipping freight, port dues, and BRTA registration fees. While it provides an accurate commercial estimate, final government assessments may vary based on actual customs physical examination at Chittagong Port.',
                'sort_order' => 5,
            ],
            [
                'category' => 'Customs & Landed Cost',
                'question' => 'What is the payment schedule for a Japan Auction Pre-order?',
                'answer' => 'We offer a transparent 4-stage milestone schedule: 1) Initial 20% booking deposit upon auction win, 2) 40% payment once export documentation and Japanese yard inspection are finalized, 3) 30% customs duty upon arrival at Chittagong Port, and 4) 10% balance upon vehicle detailing and showroom delivery.',
                'sort_order' => 6,
            ],
            [
                'category' => 'Delivery & Registration',
                'question' => 'How long does it take from winning an auction in Japan to delivery in Dhaka?',
                'answer' => 'The complete process typically takes 35 to 50 days: 7-10 days for Japanese export certification and port booking, 14-18 days for ocean transit to Chittagong Port, 7-10 days for customs assessment and port release, and 3-5 days for carrier transport to Dhaka, pre-delivery servicing, and BRTA registration.',
                'sort_order' => 7,
            ],
            [
                'category' => 'Delivery & Registration',
                'question' => 'Do you provide BRTA registration and auto financing / bank loan support?',
                'answer' => 'Yes! We manage complete BRTA registration (digital number plate, RFID tag, smart card, and fitness certification) and have partnered with major financial institutions (including Prime Bank, BRAC Bank, City Bank, and IPDC) to offer up to 70% auto loan facilities at competitive interest rates.',
                'sort_order' => 8,
            ],
        ];

        foreach ($faqs as $f) {
            Faq::updateOrCreate(
                ['question' => $f['question']],
                $f
            );
        }

        // 3. SEO Metadata Entries
        $seoPages = [
            [
                'url_path' => '/',
                'title' => 'MotoSolution Bangladesh – Japanese Reconditioned Cars & Live Auction Bidding',
                'description' => 'Explore verified Japanese reconditioned cars, bid on live Japan auctions, and calculate Bangladesh landed cost before you buy. Showroom in Niketan, Gulshan, Dhaka.',
                'keywords' => 'japanese reconditioned cars bangladesh, japan auction bid dhaka, toyota harrier bangladesh, corolla cross hybrid, motosolution gulshan',
                'canonical_url' => url('/'),
                'og_title' => 'MotoSolution – Your Dream Car, Directly From Japan',
                'og_description' => 'Verified Japanese inventory, live USS auction access, and complete Bangladesh landed cost transparency.',
                'og_image' => 'https://images.unsplash.com/photo-1549399542-7e3f8b79c341?w=1200&q=80',
                'schema_type' => 'AutoDealer',
                'sitemap_priority' => 1.0,
            ],
            [
                'url_path' => '/inventory',
                'title' => 'Ready Stock Japanese Cars in Dhaka Showroom | MotoSolution Bangladesh',
                'description' => 'Browse verified ready stock Japanese vehicles in our Gulshan showroom. High auction grade Toyotas, Hondas, and Nissans with transparent pricing.',
                'keywords' => 'ready stock cars dhaka, reconditioned car showroom gulshan, buy car dhaka, toyota ready stock bangladesh',
                'canonical_url' => url('/inventory'),
                'og_title' => 'Ready Stock Japanese Vehicles – MotoSolution Dhaka',
                'og_description' => 'Grade 4.5+ auction verified Japanese vehicles available for immediate delivery.',
                'og_image' => 'https://images.unsplash.com/photo-1590362891988-f778047831d0?w=1200&q=80',
                'schema_type' => 'AutoDealer',
                'sitemap_priority' => 0.9,
            ],
            [
                'url_path' => '/auction',
                'title' => 'Japan Live Auction Vehicles & Bidding System | MotoSolution Bangladesh',
                'description' => 'Direct live access to USS Tokyo, TAA, CAA, and HAA Japanese car auctions. View inspection sheets, countdowns, and authorize your maximum bid.',
                'keywords' => 'japan live auction cars, uss tokyo bidding bangladesh, bid on japan car, auction sheet verification dhaka',
                'canonical_url' => url('/auction'),
                'og_title' => 'Live Japan Automobile Auctions – MotoSolution',
                'og_description' => 'Real-time access to 50,000+ weekly Japanese auction lots with verified condition maps and Bangladesh landed cost calculation.',
                'og_image' => 'https://images.unsplash.com/photo-1549399542-7e3f8b79c341?w=1200&q=80',
                'schema_type' => 'AutoDealer',
                'sitemap_priority' => 0.9,
            ],
            [
                'url_path' => '/calculator',
                'title' => 'Bangladesh Car Import Cost & Duty Calculator | MotoSolution',
                'description' => 'Calculate total Bangladesh landed cost including JPY exchange rate, customs duty, supplementary duty, VAT, AIT, port charges, and BRTA registration.',
                'keywords' => 'bangladesh car import cost calculator, nbr car customs duty calculator, chittagong port landed cost, car tax bangladesh',
                'canonical_url' => url('/calculator'),
                'og_title' => 'Bangladesh Car Landed Cost & Duty Calculator – MotoSolution',
                'og_description' => 'Accurate customs duty and import bill calculator based on NBR regulations.',
                'og_image' => 'https://images.unsplash.com/photo-1550355291-bbee04a92027?w=1200&q=80',
                'schema_type' => 'AutoDealer',
                'sitemap_priority' => 0.8,
            ],
            [
                'url_path' => '/preorder',
                'title' => 'Japan Pre-Order Service – Sourced Direct From Japan | MotoSolution',
                'description' => 'Pre-order your desired Japanese car directly from auction. Choose, verify, bid, ship, and clear customs with full transparency.',
                'keywords' => 'japan car preorder bangladesh, import car from japan dhaka, custom car order bangladesh',
                'canonical_url' => url('/preorder'),
                'og_title' => 'Pre-Order Japanese Cars Direct From Auction Floor',
                'og_description' => 'Step-by-step import concierge service from Japanese auction halls to your doorstep.',
                'og_image' => 'https://images.unsplash.com/photo-1533473359331-0135ef1b58bf?w=1200&q=80',
                'schema_type' => 'AutoDealer',
                'sitemap_priority' => 0.8,
            ],
            [
                'url_path' => '/how-it-works',
                'title' => 'How It Works – 8-Step Japan Auction to Delivery Guide | MotoSolution',
                'description' => 'Learn our transparent 8-step journey: from finding your car and verifying auction sheets to Chittagong customs clearance and showroom handover.',
                'keywords' => 'how to import car from japan to bangladesh, car import process dhaka, auction sheet verification',
                'canonical_url' => url('/how-it-works'),
                'og_title' => '8-Step Transparent Vehicle Import Process',
                'og_description' => 'Find, Verify, Calculate, Bid, Ship, Clear, Register, and Deliver.',
                'og_image' => 'https://images.unsplash.com/photo-1549399542-7e3f8b79c341?w=1200&q=80',
                'schema_type' => 'AutoDealer',
                'sitemap_priority' => 0.7,
            ],
            [
                'url_path' => '/auction-sheet',
                'title' => 'Japanese Auction Sheet Verification Tool | MotoSolution Bangladesh',
                'description' => 'Verify genuine Japanese auction inspection sheets. Check genuine chassis numbers, inspect condition maps, and prevent odometer rollbacks.',
                'keywords' => 'auction sheet check bangladesh, verify japanese auction sheet, chassis number search japan',
                'canonical_url' => url('/auction-sheet'),
                'og_title' => 'Verify Any Japanese Car Auction Sheet Online',
                'og_description' => 'Authentic auction verification by MotoSolution Tokyo inspection desk.',
                'og_image' => 'https://images.unsplash.com/photo-1586281380349-632531db7ed4?w=1200&q=80',
                'schema_type' => 'AutoDealer',
                'sitemap_priority' => 0.8,
            ],
            [
                'url_path' => '/contact',
                'title' => 'Contact Us & Showroom Location | MotoSolution Bangladesh',
                'description' => 'Visit MotoSolution in Niketan, Gulshan-1, Dhaka. Call +8801714116695 or chat on WhatsApp +8801404066329 for immediate assistance.',
                'keywords' => 'motosolution contact, car showroom niketan gulshan, motosolbd phone number',
                'canonical_url' => url('/contact'),
                'og_title' => 'Contact MotoSolution – Niketan, Gulshan-1, Dhaka',
                'og_description' => 'Open Saturday to Thursday from 10:00 AM to 8:00 PM.',
                'og_image' => 'https://images.unsplash.com/photo-1549399542-7e3f8b79c341?w=1200&q=80',
                'schema_type' => 'AutoDealer',
                'sitemap_priority' => 0.7,
            ],
        ];

        foreach ($seoPages as $p) {
            SeoMeta::updateOrCreate(
                ['url_path' => $p['url_path']],
                $p
            );
        }

        // 4. System Settings
        $settings = [
            ['group' => 'company', 'key' => 'company_name', 'value' => 'MotoSolution Bangladesh', 'label' => 'Company Name'],
            ['group' => 'company', 'key' => 'tagline', 'value' => 'Your Dream Car, Directly From Japan', 'label' => 'Tagline'],
            ['group' => 'contact', 'key' => 'phone_primary', 'value' => '+8801714116695', 'label' => 'Primary Phone'],
            ['group' => 'contact', 'key' => 'whatsapp_number', 'value' => '8801404066329', 'label' => 'WhatsApp Number'],
            ['group' => 'contact', 'key' => 'email_primary', 'value' => 'info@motosolbd.com', 'label' => 'Support Email'],
            ['group' => 'contact', 'key' => 'showroom_address', 'value' => 'House 24, Road 3, Block B, Niketan, Gulshan-1, Dhaka 1212, Bangladesh', 'label' => 'Showroom Address'],
            ['group' => 'contact', 'key' => 'showroom_hours', 'value' => 'Sat - Thu: 10:00 AM - 8:00 PM (Friday Closed)', 'label' => 'Showroom Operating Hours'],
            ['group' => 'social', 'key' => 'facebook_url', 'value' => 'https://facebook.com/motosolbd', 'label' => 'Facebook Page'],
            ['group' => 'social', 'key' => 'youtube_url', 'value' => 'https://youtube.com/@motosolbd', 'label' => 'YouTube Channel'],
            ['group' => 'auction_api', 'key' => 'auction_provider_active', 'value' => 'mock', 'label' => 'Active Auction API Provider'],
        ];

        foreach ($settings as $s) {
            Setting::set($s['key'], $s['value'], $s['group'], $s['label']);
        }
    }
}
