<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Blog;
use App\Models\BlogCategory;
use App\Models\User;

class BlogSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Create blog categories
        $categories = [
            [
                'name' => 'Fish Care Tips',
                'slug' => 'fish-care-tips',
                'description' => 'Learn how to properly care for and store your fresh fish',
                'is_active' => true,
            ],
            [
                'name' => 'Recipes & Cooking',
                'slug' => 'recipes-cooking',
                'description' => 'Delicious fish recipes and cooking techniques',
                'is_active' => true,
            ],
            [
                'name' => 'Fishing Insights',
                'slug' => 'fishing-insights',
                'description' => 'Insights from professional fishermen and industry experts',
                'is_active' => true,
            ],
            [
                'name' => 'Health Benefits',
                'slug' => 'health-benefits',
                'description' => 'Nutritional information and health benefits of eating fish',
                'is_active' => true,
            ],
        ];

        foreach ($categories as $categoryData) {
            BlogCategory::firstOrCreate(
                ['slug' => $categoryData['slug']], 
                $categoryData
            );
        }

        // Get admin user (assuming first user is admin)
        $admin = User::first();
        if (!$admin) {
            $admin = User::create([
                'name' => 'Admin',
                'phone' => '01700000000',
                'email' => 'admin@fishbangladesh.com',
                'password' => bcrypt('password'),
                'is_admin' => true,
            ]);
        }

        // Create sample blogs
        $blogs = [
            [
                'title' => 'How to Keep Fish Fresh for Longer',
                'slug' => 'how-to-keep-fish-fresh-longer',
                'content' => '<p>Keeping fish fresh is crucial for maintaining its quality and taste. Here are some expert tips to help you store your fish properly:</p>

<h3>Temperature Control</h3>
<p>Always keep fish at temperatures below 4°C (40°F). Use plenty of ice and replace it regularly.</p>

<h3>Proper Storage</h3>
<p>Store fish in airtight containers or wrap them tightly in plastic wrap. This prevents air exposure and reduces bacterial growth.</p>

<h3>Time Management</h3>
<p>Fresh fish should be consumed within 1-2 days of purchase for the best quality. If you need to store it longer, consider freezing.</p>

<h3>Signs of Freshness</h3>
<ul>
<li>Clear, bright eyes</li>
<li>Firm flesh that springs back when pressed</li>
<li>Fresh ocean smell, not fishy odor</li>
<li>Bright red gills</li>
</ul>',
                'excerpt' => 'Learn expert tips on how to properly store and keep your fish fresh for longer periods.',
                'category_id' => 1,
                'author_id' => $admin->id,
                'is_published' => true,
                'is_featured' => true,
                'views_count' => 245,
                'youtube_video_url' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
                'published_at' => now()->subDays(3),
            ],
            [
                'title' => 'Traditional Bengali Fish Curry Recipe',
                'slug' => 'traditional-bengali-fish-curry-recipe',
                'content' => '<p>Bengali fish curry is a staple in Bangladeshi cuisine. This traditional recipe will transport you to the heart of Bengal with its rich flavors and aromatic spices.</p>

<h3>Ingredients</h3>
<ul>
<li>500g fresh fish (Rohu or Hilsa preferred)</li>
<li>2 medium onions, sliced</li>
<li>3-4 green chilies</li>
<li>1 tsp turmeric powder</li>
<li>2 tsp red chili powder</li>
<li>1 tsp cumin powder</li>
<li>2 tbsp mustard oil</li>
<li>Salt to taste</li>
</ul>

<h3>Cooking Method</h3>
<p>Heat mustard oil in a heavy-bottomed pan. Fry the fish pieces lightly and set aside. In the same oil, add onions and cook until golden brown.</p>

<p>Add spices and cook for 2-3 minutes. Add water to make a gravy and bring to boil. Add the fried fish and simmer for 10-15 minutes.</p>

<h3>Serving Suggestion</h3>
<p>Serve hot with steamed rice and enjoy this authentic Bengali delicacy.</p>',
                'excerpt' => 'Master the art of cooking traditional Bengali fish curry with this authentic recipe passed down through generations.',
                'category_id' => 2,
                'author_id' => $admin->id,
                'is_published' => true,
                'is_featured' => true,
                'views_count' => 432,
                'facebook_video_url' => 'https://www.facebook.com/watch/?v=123456789',
                'published_at' => now()->subDays(2),
            ],
            [
                'title' => 'Sustainable Fishing Practices in Bangladesh',
                'slug' => 'sustainable-fishing-practices-bangladesh',
                'content' => '<p>Sustainable fishing is crucial for preserving our marine ecosystem and ensuring fish availability for future generations. Bangladesh has implemented several initiatives to promote responsible fishing.</p>

<h3>Current Practices</h3>
<p>Local fishermen are adopting modern techniques that minimize environmental impact while maximizing catch quality.</p>

<h3>Government Initiatives</h3>
<p>The Bangladesh government has introduced fishing quotas and seasonal restrictions to protect fish populations during breeding seasons.</p>

<h3>Community Involvement</h3>
<p>Fishing communities are working together to establish sustainable practices and share knowledge about responsible fishing methods.</p>

<h3>Future Outlook</h3>
<p>With continued efforts, Bangladesh aims to become a leader in sustainable aquaculture and fishing practices in South Asia.</p>',
                'excerpt' => 'Explore how Bangladesh is leading the way in sustainable fishing practices to preserve marine ecosystems.',
                'category_id' => 3,
                'author_id' => $admin->id,
                'is_published' => true,
                'is_featured' => true,
                'views_count' => 189,
                'published_at' => now()->subDays(1),
            ],
            [
                'title' => 'Health Benefits of Eating Fish Regularly',
                'slug' => 'health-benefits-eating-fish-regularly',
                'content' => '<p>Fish is one of the most nutritious foods available, packed with high-quality protein, omega-3 fatty acids, and essential vitamins and minerals.</p>

<h3>Omega-3 Fatty Acids</h3>
<p>Fish is rich in omega-3 fatty acids, which are essential for heart health, brain function, and reducing inflammation.</p>

<h3>High-Quality Protein</h3>
<p>Fish provides complete protein with all essential amino acids needed for muscle building and repair.</p>

<h3>Vitamins and Minerals</h3>
<p>Fish is an excellent source of:</p>
<ul>
<li>Vitamin D for bone health</li>
<li>Vitamin B12 for nerve function</li>
<li>Iodine for thyroid function</li>
<li>Selenium for immune system</li>
</ul>

<h3>Heart Health</h3>
<p>Regular fish consumption is linked to reduced risk of heart disease and stroke.</p>

<h3>Brain Development</h3>
<p>DHA in fish is crucial for brain development in children and cognitive function in adults.</p>',
                'excerpt' => 'Discover the incredible health benefits of including fish in your regular diet and why it\'s considered a superfood.',
                'category_id' => 4,
                'author_id' => $admin->id,
                'is_published' => true,
                'is_featured' => true,
                'views_count' => 356,
                'youtube_video_url' => 'https://www.youtube.com/watch?v=example123',
                'published_at' => now(),
            ],
            [
                'title' => 'Best Time to Buy Fresh Hilsa Fish',
                'slug' => 'best-time-buy-fresh-hilsa-fish',
                'content' => '<p>Hilsa, the national fish of Bangladesh, has specific seasons when it\'s at its peak quality and flavor. Understanding these cycles can help you get the best fish for your money.</p>

<h3>Peak Season</h3>
<p>The best time to buy Hilsa is during the monsoon season (June to October) when the fish migrate from the sea to rivers for breeding.</p>

<h3>Quality Indicators</h3>
<p>During peak season, Hilsa fish are:</p>
<ul>
<li>Fuller with more oil content</li>
<li>Have a shinier appearance</li>
<li>Taste more delicious</li>
<li>Are generally larger in size</li>
</ul>

<h3>Pricing</h3>
<p>While peak season offers the best quality, prices may be higher due to demand. Early morning markets often have better prices and fresher stock.</p>

<h3>Storage Tips</h3>
<p>If you buy during peak season, you can clean and freeze portions for later use throughout the year.</p>',
                'excerpt' => 'Learn when to buy the finest Hilsa fish and how to identify premium quality during different seasons.',
                'category_id' => 1,
                'author_id' => $admin->id,
                'is_published' => true,
                'is_featured' => false,
                'views_count' => 178,
                'published_at' => now()->subDays(5),
            ],
        ];

        foreach ($blogs as $blogData) {
            Blog::firstOrCreate(
                ['slug' => $blogData['slug']], 
                $blogData
            );
        }
    }
}
