<?php

namespace Database\Factories;

use App\Models\Certificate;
use App\Models\Education;
use App\Models\Engineer;
use App\Models\Experience;
use App\Models\PortfolioProject;
use App\Models\Project;
use App\Models\Service;
use App\Models\User;
use App\Models\Wallet;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Engineer>
 */
class EngineerFactory extends Factory
{

    /**
     * Configure the model factory.
     *
     * @return $this
     */
    public function configure()
    {
        return $this->afterCreating(function (Engineer $engineer) {
            $engineer->skills()->attach([1,2]);
            $engineer->addLocation([
                'long'=> 31.233334,
                'lat'=> 30.033333,
                'address' => 'Cairo, Egypt',
            ]);
                        // Test Add phone
            $engineer->addPhone([
                'number'=>'155555555',
                'code'=>'EG',
            ]);

            $engineer->categories()->attach([15,16,17]);
            $engineer->addSocials([
                'facebook'=>$this->faker->url,
                'instagram'=>$this->faker->url,
            ]);
            $engineer->addCurrency(1);
            $engineer->experiences()->save(Experience::factory()->create([
                'engineer_id'=>$engineer->id,
            ]));
            $engineer->educations()->save(Education::factory()->create([
                'engineer_id'=>$engineer->id,
            ]));
            $engineer->certificates()->save(Certificate::factory()->create([
                'engineer_id'=>$engineer->id,
            ]));
            $engineer->portfolioProjects()->save(PortfolioProject::factory()->create([
                'portfolioable_id'=>$engineer->id,
                'portfolioable_type'=>'App\Models\Engineer',
            ]));

            $engineer->services()->save(Service::factory()->create());

            $engineer->addMastery(1,5);
//            $engineer->projects()->saveMany(Project::factory(3)->create(
//                [
//                    'projectable_id'=>$engineer->id,
//                    'projectable_type'=>'App\Models\Engineer',
//                ]
//            ));
            $engineer->wallet()->save(Wallet::factory()->create());
        });
    }
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition()
    {
        return [
            'name' => $this->faker->name(),
            'email' => $this->faker->email(),
            'tag_line' => $this->faker->sentence(),
            'about' => $this->faker->paragraph(),
            'level_of_experience_id' => $this->faker->numberBetween(1, 3),
            'daily_rate' => $this->faker->numberBetween(50, 300),
            'monthly_rate' => $this->faker->numberBetween(50, 300),
            'yearly_rate' => $this->faker->numberBetween(50, 300),
            'category_id' => 1,
            'engineering_licence_number' => $this->faker->unique()->randomNumber(),
            'engineering_licence_path' => $this->faker->imageUrl(),
            'engineering_degree_path' => $this->faker->imageUrl(),
            'passport_path' => $this->faker->imageUrl(),
            'cv_path' => $this->faker->imageUrl(),
            'user_id' => User::factory(),
        ];
    }
}
