<?php

namespace Database\Factories;

use App\Enums\EmploymentStatus;
use App\Enums\Gender;
use App\Models\Employee;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

class EmployeeFactory extends Factory
{
    protected $model = Employee::class;

    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'full_name' => $this->faker->name(),
            'code' => Employee::generateEmployeeCode(),
            'phone_number' => $this->faker->randomElement([
                $this->faker->numerify('0812 #### ###'),
                $this->faker->numerify('0812 #### ####'),
                $this->faker->numerify('0812 #### #####'),
            ]),
            'base_salary' => $this->faker->randomNumber(6),
            'birthdate' => $this->faker->dateTimeBetween('-60 years', '-18 years')->format('Y-m-d'),
            'hire_date' => $this->faker->date(),
            'gender' => $this->faker->randomElement(Gender::cases()),
            'status' => $this->faker->randomElement(EmploymentStatus::cases()),
        ];
    }

    public function withAddress(): Factory
    {
        return $this->state(fn () => ['address' => $this->faker->address()]);
    }

    public function resigned(): Factory
    {
        return $this->state(fn () => ['resign_date' => $this->faker->date()]);
    }

    public function male(): Factory
    {
        return $this->state(fn () => ['gender' => Gender::MALE]);
    }

    public function female(): Factory
    {
        return $this->state(fn () => ['gender' => Gender::FEMALE]);
    }

    public function permanent(): Factory
    {
        return $this->state(fn () => ['status' => EmploymentStatus::PERMANENT]);
    }

    public function contract(): Factory
    {
        return $this->state(fn () => ['status' => EmploymentStatus::CONTRACT]);
    }

    public function intern(): Factory
    {
        return $this->state(fn () => ['status' => EmploymentStatus::INTERN]);
    }
}
