<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\User;
use App\Models\Car;
class RepairOrderFactory extends Factory
{
protected $model = \App\Models\RepairOrder::class;
public function definition(): array
{
$orderDate = $this->faker->dateTimeBetween('-6 months', 'now');
$completionDate = $this->faker->optional(0.7)->dateTimeBetween($orderDate, '+1 month');
return [
'order_number' => 'ORD-' . strtoupper($this->faker->bothify('#####')),
'user_id' => User::factory()->user(),
'car_id' => Car::factory(),
'admin_id' => $this->faker->optional(0.5)->passthrough(User::factory()->admin()),
'status' => $this->faker->randomElement(['pending', 'in_progress', 'completed', 'cancelled']),
'order_date' => $orderDate,
'completion_date' => $completionDate,
'problem_description' => $this->faker->realText(200),
'admin_notes' => $this->faker->optional(0.5)->realText(100),
'total_labor_cost' => 0,
'total_parts_cost' => 0,
'total_amount' => 0,
];
}
public function pending()
{
return $this->state(function (array $attributes) {
return ['status' => 'pending', 'completion_date' => null];
});
}
public function inProgress()
{
return $this->state(function (array $attributes) {
return ['status' => 'in_progress', 'completion_date' => null];
});
}
public function completed()
{
return $this->state(function (array $attributes) {
return [
'status' => 'completed',
'completion_date' => $this->faker->dateTimeBetween('-1 month', 'now'),
];
});
}
public function cancelled()
{
return $this->state(function (array $attributes) {
return ['status' => 'cancelled', 'completion_date' => null];
});
}
}