<?php
namespace Database\Factories;
use App\Modules\Catalog\Models\Inventory;
use App\Modules\Catalog\Models\Product;
use App\Modules\Vendor\Models\Vendor;
use Illuminate\Database\Eloquent\Factories\Factory;
class InventoryFactory extends Factory
{
protected $model = Inventory::class;
public function definition(): array
{
return [
'product_id' => Product::factory(),
'vendor_id' => Vendor::factory(),
'variant_id' => null,
'quantity' => fake()->numberBetween(10, 100),
'reserved_quantity' => 0,
'low_stock_threshold' => 5,
'allow_backorder' => false,
'track_inventory' => true,
'last_restocked_at' => now()->subDays(fake()->numberBetween(1, 30)),
];
}
public function lowStock(): static
{
return $this->state([
'quantity' => fake()->numberBetween(1, 4),
'low_stock_threshold' => 5,
]);
}
public function outOfStock(): static
{
return $this->state([
'quantity' => 0,
'low_stock_threshold' => 5,
'allow_backorder' => false,
]);
}
public function withBackorder(): static
{
return $this->state([
'quantity' => 0,
'allow_backorder' => true,
]);
}
}