<?php

namespace Database\Factories;

use App\Models\PaymentManagement\Payment;
use App\Models\SecurityManagement\Role;
use App\Models\UserManagement\Customer;
use App\Models\UserManagement\User;
use App\Models\UserManagement\UserType;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class CustomerFactory extends Factory{

    protected $model = Customer::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition(){
        return [
            'first_name' => $this->faker->firstName,
            'last_name' => $this->faker->lastName,
            'username' => $this->faker->unique()->userName,
            'email' => $this->faker->unique()->safeEmail,
            'email_verified_at' => now(),
            'phone' => $this->faker->unique()->phoneNumber,
            'password' => bcrypt('123456'),
            'active' => true,
            'remember_token' => Str::random(10),
        ];
    }

    public function configure(){
        return $this->afterCreating(function (Customer $customer) {
          //  $customer->assignRole(Role::CUSTOMER);
//            $payment = Payment::factory(1)->make();
//            $customer->payments()->create($payment->toArray());
            $this->has(Payment::factory(1),"payments");
        });
    }

    public function unverified(): \Illuminate\Database\Eloquent\Factories\Factory{
        return $this->state(function (array $attributes) {
            return [
                'email_verified_at' => now(),
            ];
        });
    }


    public function withpayments(): \Illuminate\Database\Eloquent\Factories\Factory{
        return $this->state(function (array $attributes) {
             $this->has(Payment::factory()->count(1),"payments");
            return [];
        });
    }


}
