<?php

namespace Database\Factories;

use App\Models\Harvest;
use App\Models\Treatment;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PlannedTask>
 */
class PlannedTaskFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $plannedDate = fake()->dateTimeBetween('-1 week', '+3 weeks');

        return [
            'planned_date' => $plannedDate,
            'execution_date' => fake()->optional()->dateTimeBetween($plannedDate, '+2 months'),
            'type' => 'treatment',
            'note' => fake()->optional()->sentence(10),
            'taskable_type' => Treatment::class,
            'taskable_id' => Treatment::factory(),
        ];
    }

    /**
     * Target a specific treatment.
     */
    public function forTreatment(Treatment $treatment): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => 'treatment',
            'taskable_type' => Treatment::class,
            'taskable_id' => $treatment->getKey(),
        ]);
    }

    /**
     * Target a specific harvest.
     */
    public function forHarvest(Harvest $harvest): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => 'harvest',
            'taskable_type' => Harvest::class,
            'taskable_id' => $harvest->getKey(),
        ]);
    }
}
