<?php

namespace Database\Factories;

use App\Models\ServiceOrder;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<ServiceOrder>
 */
class ServiceOrderFactory extends Factory
{
    /**
     * Configure the model factory.
     *
     * @return $this
     */
    public function configure()
    {

        return $this->afterCreating(function (ServiceOrder $serviceOrder) {
            $service = $serviceOrder->service;
            $serviceOrder->addMilestone([
                'name' => $service->title,
                'amount' => $service->getTierPrice(1),
                'duration' => $service->getTierDuration(1),
                'deliverables' => array_values($service->tierOptions()->where($service->getTierEnabled(1), 1)->get('title as name')->toArray()),
            ]);
        });
    }
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition()
    {
        return [
            'service_id' => $this->faker->numberBetween(1, 5),
            'user_id' => User::factory(),
            'tier' => $this->faker->numberBetween(1, 3),
        ];
    }
}
