<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class BlogSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Get a valid user ID from the database
        $userId = DB::table('users')->value('id');

        // Get actual category IDs from the database
        $categories = DB::table('blog_categories')->pluck('id', 'name')->toArray();

        $blogs = [
            [
                'author_id' => $userId,
                'title' => 'The Future of Technology',
                'header' => 'Exploring upcoming trends in tech',
                'image_url' => 'https://example.com/images/tech_blog.jpg',
                'content' => 'This is a detailed blog post about the future of technology.',
                'category_id' => $categories['Technology'] ?? null,
                'read_count' => 100,
                'minute_read' => 5,
                'slug' => 'the-future-of-technology',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'author_id' => $userId,
                'title' => 'Healthy Living Tips',
                'header' => 'Simple steps to improve your health',
                'image_url' => 'https://example.com/images/health_blog.jpg',
                'content' => 'This blog shares some simple tips for healthy living.',
                'category_id' => $categories['Health'] ?? null,
                'read_count' => 250,
                'minute_read' => 3,
                'slug' => 'healthy-living-tips',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'author_id' => $userId,
                'title' => 'Personal Finance Basics',
                'header' => 'Managing your finances the right way',
                'image_url' => 'https://example.com/images/finance_blog.jpg',
                'content' => 'This blog post discusses the basics of personal finance management.',
                'category_id' => $categories['Business'] ?? null,
                'read_count' => 50,
                'minute_read' => 7,
                'slug' => 'personal-finance-basics',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'author_id' => $userId,
                'title' => 'How to Improve Your Lifestyle',
                'header' => 'Simple ways to make life better',
                'image_url' => 'https://example.com/images/lifestyle_blog.jpg',
                'content' => 'This blog post shares tips and ideas to improve your lifestyle.',
                'category_id' => $categories['Lifestyle'] ?? null,
                'read_count' => 300,
                'minute_read' => 4,
                'slug' => 'how-to-improve-your-lifestyle',
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ];

        // Insert blogs into the database
        foreach ($blogs as $blog) {
            DB::table('blogs')->insert(array_merge($blog, [
                'id' => (string) Str::uuid(),
                'created_at' => now(),
                'updated_at' => now(),
            ]));
        }
    }
}
