<?php
namespace Database\Seeders;

use App\Models\Category;
use App\Models\Product;
use App\Models\Vendor;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class VendorSeeder extends Seeder
{
    public function run(): void
    {
        $vendor = Vendor::where('slug', 'demo-electronics-store')->first();
        if (!$vendor) return;

        $category = Category::where('is_global', true)->first();

        $products = [
            ['name' => 'iPhone 15 Pro Max', 'price' => 1199.99, 'sale_price' => 1099.99, 'stock' => 50],
            ['name' => 'Samsung Galaxy S24', 'price' => 999.99, 'sale_price' => 879.99, 'stock' => 40],
            ['name' => 'MacBook Pro M3', 'price' => 2499.99, 'sale_price' => null, 'stock' => 20],
            ['name' => 'Sony WH-1000XM5 Headphones', 'price' => 399.99, 'sale_price' => 349.99, 'stock' => 100],
            ['name' => 'iPad Air 11"', 'price' => 749.99, 'sale_price' => 699.99, 'stock' => 30],
            ['name' => 'Apple Watch Series 9', 'price' => 499.99, 'sale_price' => null, 'stock' => 60],
        ];

        foreach ($products as $p) {
            Product::create([
                'vendor_id'        => $vendor->id,
                'category_id'      => $category?->id,
                'name'             => $p['name'],
                'slug'             => Str::slug($p['name']) . '-' . Str::random(6),
                'short_description' => "High quality {$p['name']} available at great price.",
                'description'      => "<p>This is the <strong>{$p['name']}</strong>. A premium product from our store with excellent build quality and performance.</p>",
                'price'            => $p['price'],
                'sale_price'       => $p['sale_price'],
                'sku'              => 'SKU-' . strtoupper(Str::random(8)),
                'stock_quantity'   => $p['stock'],
                'track_inventory'  => true,
                'stock_status'     => 'in_stock',
                'status'           => 'published',
                'is_featured'      => true,
                'average_rating'   => rand(35, 50) / 10,
                'review_count'     => rand(5, 200),
                'sales_count'      => rand(10, 500),
            ]);
        }

        $this->command->info('Sample products seeded for demo vendor.');
    }
}
