<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Enums\EmployeeStatus;
use App\Models\Employee;
use App\Models\Location;
use App\Models\Team;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * Test data only.
 *
 * @extends Factory<Employee>
 */
class EmployeeFactory extends Factory
{
    // The return shape is inherited from Factory<Employee>::definition().
    public function definition(): array
    {
        return [
            'employee_code' => 'AUM'.$this->faker->unique()->numerify('#####'),
            'first_name' => fake()->firstName(),
            'last_name' => fake()->lastName(),
            'email' => fake()->unique()->safeEmail(),
            'personal_email' => null,
            'phone' => fake()->numerify('##########'),
            'team_id' => null,
            'designation' => fake()->randomElement([
                'Software Engineer', 'QA Engineer', 'HR Executive', 'Accountant',
                'Operations Associate', 'Product Designer', 'Delivery Manager',
            ]),
            'squad' => null,
            'location_id' => null,
            'status' => EmployeeStatus::Active,
            'date_of_joining' => fake()->dateTimeBetween('-5 years', 'now')->format('Y-m-d'),
            'date_of_exit' => null,
            'notes' => null,
        ];
    }

    public function onNotice(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => EmployeeStatus::OnNotice,
        ]);
    }

    public function exited(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => EmployeeStatus::Exited,
            'date_of_exit' => fake()->dateTimeBetween('-30 days', 'now')->format('Y-m-d'),
        ]);
    }

    public function inactive(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => EmployeeStatus::Inactive,
        ]);
    }

    public function inTeam(Team $team): static
    {
        return $this->state(fn (array $attributes): array => [
            'team_id' => $team->getKey(),
        ]);
    }

    public function atLocation(Location $location): static
    {
        return $this->state(fn (array $attributes): array => [
            'location_id' => $location->getKey(),
        ]);
    }

    public function inSquad(string $squad): static
    {
        return $this->state(fn (array $attributes): array => [
            'squad' => $squad,
        ]);
    }

    public function withoutLastName(): static
    {
        return $this->state(fn (array $attributes): array => [
            'last_name' => null,
        ]);
    }
}
