<?php

namespace Database\Factories;

use App\Enums\ChickenStatus;
use App\Models\Chicken;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories.Factory<\App\Models\Chicken>
 */
class ChickenFactory extends Factory
{
    protected $model = Chicken::class;

    public function definition(): array
    {
        $arrivalDate = $this->faker->dateTimeBetween('-6 months', 'now');
        $hatchDate = $this->faker->boolean(70)
            ? $this->faker->dateTimeBetween(
                (clone $arrivalDate)->modify('-2 months'),
                $arrivalDate
            )
            : null;

        $status = $this->faker->randomElement(ChickenStatus::cases());
        $exitDate = $status === ChickenStatus::DEAD
            ? $this->faker->dateTimeBetween($arrivalDate, 'now')
            : null;

        return [
            'tag_code' => strtoupper($this->faker->bothify('CHK-###??')),
            'hatch_date' => $hatchDate,
            'arrival_date' => $arrivalDate,
            'exit_date' => $exitDate,
            'status' => $status,
        ];
    }
}
