<?php

namespace Database\Seeders;

use App\Enums\Concentration;
use App\Models\Brand;
use App\Models\Category;
use App\Models\Outlet;
use App\Models\Perfume;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class PerfumeSeeder extends Seeder
{
    public function run(): void
    {
        $perfumeNames = [
            'Amber Woods',
            'Velvet Oud',
            'Citrus Bloom',
            'Midnight Musk',
            'Ocean Whisper',
            'Rose Eclipse',
            'Golden Sand',
            'Spiced Leather',
            'Vanilla Sky',
            'Emerald Breeze',
        ];

        $brands = Brand::orderBy('sort_order')->get();

        foreach ($perfumeNames as $index => $name) {
            $brand = $brands[$index % $brands->count()];
            $slug = Str::slug($name);
            $sku = Str::upper(Str::random(3)).'-'.str_pad($index + 1, 4, '0', STR_PAD_LEFT);

            $salePrice = fake()->numberBetween(25, 50) * 100;

            $perfume = Perfume::create([
                'brand_id' => $brand->id,
                'name' => $name,
                'slug' => $slug,
                'sku' => $sku,
                'concentration' => fake()->randomElement(Concentration::values()),
                'cost_price' => fake()->numberBetween(5, 11) * 100,
                'sale_price' => $salePrice,
                'point_per_ml' => round($salePrice / 100),
                'base_notes' => fake()->optional()->randomElement(['Amber', 'Musk', 'Vanilla', 'Sandalwood', 'Leather']),
                'middle_notes' => fake()->optional()->randomElement(['Rose', 'Jasmine', 'Patchouli', 'Cedarwood', 'Iris']),
                'top_notes' => fake()->optional()->randomElement(['Citrus', 'Bergamot', 'Pepper', 'Mint', 'Lavender']),
                'description' => fake()->optional()->sentence(10),
            ]);

            $perfume->categories()->attach(fake()->randomElements(Category::all()->pluck('id')->toArray(), 2));
            $perfume->outlets()->attach(Outlet::all()->pluck('id')->toArray());
        }
    }
}
