<?php

namespace Database\Factories;

use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

/**
 * @extends Factory<User>
 */
class UserFactory extends Factory
{
    /**
     * The current password being used by the factory.
     */
    protected static ?string $password;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $firstName = fake()->firstName();
        $lastName = fake()->lastName();

        return [
            'uuid' => (string) Str::uuid(),
            'profile_photo' => null,
            'first_name' => $firstName,
            'last_name' => $lastName,
            'full_name' => $firstName.' '.$lastName,
            'mobile' => fake()->unique()->numerify('+91##########'),
            'alternate_mobile' => null,
            'email' => fake()->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password' => static::$password ??= Hash::make('StrongPassword!123'),
            'country_code' => '+91',
            'country' => 'India',
            'state' => fake()->state(),
            'city' => fake()->city(),
            'address' => fake()->streetAddress(),
            'pincode' => fake()->postcode(),
            'gender' => fake()->randomElement(['male', 'female', 'other', 'prefer_not_to_say']),
            'date_of_birth' => fake()->dateTimeBetween('-70 years', '-18 years')->format('Y-m-d'),
            'device_limit' => 1,
            'subscription_id' => null,
            'wallet_balance' => fake()->randomFloat(2, 0, 10000),
            'referral_code' => Str::upper(Str::random(10)),
            'referred_by' => null,
            'mobile_verified_at' => now(),
            'status' => 'active',
            'account_status' => 'verified',
            'is_premium' => false,
            'language' => 'en',
            'timezone' => 'Asia/Kolkata',
            'last_login' => fake()->optional()->dateTimeBetween('-30 days'),
            'last_ip' => fake()->optional()->ipv4(),
            'firebase_uid' => null,
            'fcm_token' => null,
            'remember_token' => Str::random(10),
        ];
    }

    /**
     * Indicate that the model's email address should be unverified.
     */
    public function unverified(): static
    {
        return $this->state(fn (array $attributes) => [
            'email_verified_at' => null,
        ]);
    }

    public function pending(): static
    {
        return $this->state(fn (): array => [
            'status' => 'pending',
            'account_status' => 'email_pending',
            'email_verified_at' => null,
            'mobile_verified_at' => null,
        ]);
    }

    public function premium(): static
    {
        return $this->state(fn (): array => [
            'is_premium' => true,
            'account_status' => 'premium',
            'device_limit' => 5,
        ]);
    }

    public function blocked(): static
    {
        return $this->state(fn (): array => ['status' => 'blocked']);
    }

    public function suspended(): static
    {
        return $this->state(fn (): array => ['status' => 'suspended']);
    }
}
