66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\ShiftDayEnum;
|
|
use App\Enums\UserEnum;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Shift>
|
|
*/
|
|
class ShiftFactory extends Factory
|
|
{
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'day_of_week' => fake()->randomElement(ShiftDayEnum::cases())->value,
|
|
'date' => null,
|
|
'start_time' => '08:00',
|
|
'end_time' => '16:00',
|
|
'is_active' => true,
|
|
'user_id' => null,
|
|
'created_by' => null,
|
|
];
|
|
}
|
|
|
|
public function onDate(string $date): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'day_of_week' => null,
|
|
'date' => $date,
|
|
]);
|
|
}
|
|
|
|
public function weekly(ShiftDayEnum $day): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'day_of_week' => $day->value,
|
|
'date' => null,
|
|
]);
|
|
}
|
|
|
|
public function between(string $start, string $end): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'start_time' => $start,
|
|
'end_time' => $end,
|
|
]);
|
|
}
|
|
|
|
public function forDoctor(?User $doctor = null): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'user_id' => $doctor?->id ?? User::factory()->state(['level' => UserEnum::Doctor->value]),
|
|
]);
|
|
}
|
|
|
|
public function inactive(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'is_active' => false,
|
|
]);
|
|
}
|
|
}
|