<?php

namespace Database\Factories;

use App\Enums\ChargeBasis;
use App\Models\Product;
use App\Models\ProductCategory;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends Factory<Product>
 */
class ProductFactory extends Factory
{
    protected $model = Product::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $name = fake()->words(3, true);

        return [
            'category_id' => ProductCategory::factory(),
            'name' => Str::title($name),
            'code' => Str::upper(Str::slug($name, '-')).'-'.fake()->unique()->numberBetween(100, 999),
            'description' => fake()->optional()->sentence(),
            'unit' => fake()->randomElement(['each', 'hour', 'day', 'person', 'plate']),
            'default_price' => fake()->randomFloat(2, 100, 10000),
            'default_tax_rate' => fake()->randomElement([0, 16]),
            'default_charge_basis' => fake()->randomElement(ChargeBasis::cases()),
            'min_qty' => 1,
            'max_qty' => fake()->optional()->numberBetween(10, 1000),
            'is_active' => true,
            'internal_notes' => fake()->optional()->sentence(),
        ];
    }
}
