<?php

namespace Database\Factories;

use App\Enums\LeaveRequestStatus;
use App\Models\Employee;
use App\Models\LeaveRequest;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<LeaveRequest>
 */
class LeaveRequestFactory extends Factory
{
    public function definition(): array
    {
        $startDate = fake()->dateTimeBetween('now', '+2 months');
        $totalDays = fake()->numberBetween(1, 5);
        $endDate = (clone $startDate)->modify('+'.($totalDays - 1).' days');

        return [
            'employee_id' => Employee::factory(),
            'start_date' => $startDate,
            'end_date' => $endDate,
            'total_days' => $totalDays,
            'status' => LeaveRequestStatus::PENDING->value,
            'verified_at' => null,
            'verified_by_id' => null,
        ];
    }

    public function approved(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => LeaveRequestStatus::APPROVED->value,
            'verified_at' => now(),
            'verified_by_id' => User::factory(),
        ]);
    }

    public function rejected(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => LeaveRequestStatus::REJECTED->value,
            'verified_at' => now(),
            'verified_by_id' => User::factory(),
        ]);
    }
}
