<?php

namespace Database\Factories\Client;

use App\Models\LeadSource\LeadSource;
use App\Models\LeadSource\LeadSourceEndpoint;
use App\Models\Solicitor\Solicitor;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
 */
class ClientFactory extends Factory {
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array {
        $leadSource = LeadSource::factory()
            ->has(
                LeadSourceEndpoint::factory(),
                'endpoints'
            )
            ->create();

        $endpoint = $leadSource->endpoints->random();

        return [
            'solicitor_id' => $this->faker->optional(0.7)->randomElement(
                Solicitor::pluck('id')->toArray()
            ),
            'slug' => $this->faker->uuid(),
            'name_first' => $this->faker->firstName(),
            'name_last' => $this->faker->lastName(),
            'email_address' => $this->faker->unique()->safeEmail(),
            'phone_number' => '+447' . $this->faker->randomNumber(9, true),
            'date_of_birth' => $this->faker->date(),
            'lead_source_id' => $leadSource->id,
            'lead_source_endpoint_id' => $endpoint->id,
            'created_at' => $this->faker->dateTimeBetween('-3 months'),
        ];
    }

}
