125 lines
3.8 KiB
PHP
125 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\NutritionPlanSource;
|
|
use App\Enums\PacePreference;
|
|
use App\Enums\PhysicalActivityLevel;
|
|
use App\Enums\UserRole;
|
|
use App\Enums\UserSex;
|
|
use App\Enums\WeightGoal;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\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
|
|
{
|
|
return [
|
|
'name' => fake()->name(),
|
|
'email' => fake()->unique()->safeEmail(),
|
|
'locale' => 'en',
|
|
'role' => UserRole::USER,
|
|
'email_verified_at' => now(),
|
|
'password' => static::$password ??= Hash::make('password'),
|
|
'avatar_url' => null,
|
|
'height' => 175,
|
|
'target_weight' => 70,
|
|
'date_of_birth' => '1990-01-01',
|
|
'sex' => UserSex::MAN,
|
|
'physical_activity_level' => PhysicalActivityLevel::MODERATELY_ACTIVE,
|
|
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT,
|
|
'pace_preference' => PacePreference::NORMAL,
|
|
'onboarding_completed_at' => now(),
|
|
'nutrition_estimate_accepted_at' => now(),
|
|
'remember_token' => Str::random(10),
|
|
];
|
|
}
|
|
|
|
public function configure(): static
|
|
{
|
|
return $this->afterCreating(function (User $user): void {
|
|
if (! $user->hasCompletedNutritionOnboarding()) {
|
|
return;
|
|
}
|
|
|
|
$user->weightEntries()->create([
|
|
'weight_kg' => 70,
|
|
'measured_at' => now(),
|
|
]);
|
|
|
|
$user->nutritionPlans()->create([
|
|
'source' => NutritionPlanSource::ONBOARDING,
|
|
'formula_version' => 'mifflin_st_jeor_v1',
|
|
'calories' => 2200,
|
|
'proteins' => 112,
|
|
'carbs' => 286,
|
|
'fats' => 61,
|
|
'resting_metabolism' => 1650,
|
|
'maintenance_calories' => 2200,
|
|
'calorie_adjustment_percent' => 0,
|
|
'calculation_details' => [
|
|
'activityFactor' => 1.55,
|
|
'inputWeightKg' => 70,
|
|
],
|
|
'effective_from' => now(),
|
|
]);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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 onboarded(): static
|
|
{
|
|
return $this->state(fn (array $attributes): array => [
|
|
'height' => 175,
|
|
'target_weight' => 70,
|
|
'date_of_birth' => '1990-01-01',
|
|
'sex' => UserSex::MAN,
|
|
'physical_activity_level' => PhysicalActivityLevel::MODERATELY_ACTIVE,
|
|
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT,
|
|
'pace_preference' => PacePreference::NORMAL,
|
|
'onboarding_completed_at' => now(),
|
|
'nutrition_estimate_accepted_at' => now(),
|
|
]);
|
|
}
|
|
|
|
public function withoutNutritionOnboarding(): static
|
|
{
|
|
return $this->state(fn (array $attributes): array => [
|
|
'height' => null,
|
|
'target_weight' => null,
|
|
'date_of_birth' => null,
|
|
'sex' => null,
|
|
'physical_activity_level' => null,
|
|
'weight_goal' => null,
|
|
'pace_preference' => null,
|
|
'onboarding_completed_at' => null,
|
|
'nutrition_estimate_accepted_at' => null,
|
|
]);
|
|
}
|
|
}
|