<?php

namespace Database\Factories;

use App\Models\Location;
use App\Models\Rating;
use App\Models\Service;
use App\Models\ServiceImage;
use App\Models\ServiceOrder;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Service>
 */
class ServiceFactory extends Factory
{

    /**
     * Configure the model factory.
     *
     * @return $this
     */
    public function configure()
    {
        return $this->afterCreating(function (Service $service) {
            $service->skills()->attach([1,2]);
            $service->location()->save(Location::factory()->create());
            $service->categories()->attach([45,46,47,48]);
            $user = User::inRandomOrder()->first();

            if($service->id%10==0){
                $service->categories()->attach([8]);
                $service->skills()->attach([3,4,5]);
                $user->like($service);
            }

            $service->images()->saveMany(ServiceImage::factory(2)->create([
                'service_id'=>$service->id,
            ]));

            $service->rates()->saveMany(Rating::factory(3)->create());

//            $user->serviceOrders()->save(ServiceOrder::factory()->create([
//                'service_id'=>$service->id,
//                'user_id'=>$user->id,
//            ]));
        });
    }
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition()
    {
        return [
            'title' => $this->faker->name,
            'description' => $this->faker->text,
            'three_tiers' => $this->faker->boolean,
            'slug'=>$this->faker->uuid,
            'basic_tier_price' => $this->faker->numberBetween(1, 5000),
            'pro_tier_price' => $this->faker->numberBetween(1, 5000),
            'standard_tier_price' => $this->faker->numberBetween(1, 5000),
            'standard_tier_days' => $this->faker->numberBetween(1, 20),
            'pro_tier_days' => $this->faker->numberBetween(1, 20),
            'basic_tier_days' => $this->faker->numberBetween(1, 20),
            'category_id' => $this->faker->numberBetween(1, 3),
            'serviceable_id' => $this->faker->numberBetween(1, 5),
            'serviceable_type' => $this->faker->randomElement(['App\Models\Engineer','App\Models\Firm']),
            'status' => 'Published',
        ];
    }
}
