<?php

namespace Database\Seeders;

use App\Models\Outlet;
use App\Models\Product;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class ProductSeeder extends Seeder
{
    public function run(): void
    {
        $products = [
            'Kurma Ajwa',
            'Kurma Medjool',
            'Siwak Al Miswak',
            'Minyak Wangi Kasturi',
            'Tasbih Kayu Cendana',
            'Sorban Putih Premium',
            'Kitab Riyadhus Shalihin',
            'Kitab Arbain Nawawi',
            'Kapsul Habbatussauda',
            'Air Zamzam 1L',
        ];

        foreach ($products as $index => $name) {
            $slug = Str::slug($name);
            $sku = Str::upper(Str::random(3)).'-'.str_pad($index + 1, 4, '0', STR_PAD_LEFT);

            $salePrice = fake()->numberBetween(15, 200) * 1000;

            $product = Product::create([
                'name' => $name,
                'slug' => $slug,
                'sku' => $sku,
                'cost_price' => fake()->numberBetween(15, 80) * 1000,
                'sale_price' => $salePrice,
                'point_per_pcs' => round($salePrice / 100),
                'description' => fake()->sentence(12),
            ]);

            $product->outlets()->attach(Outlet::all()->pluck('id')->toArray());
        }
    }
}
