74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\WeeklyReviewStatus;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class WeeklyReview extends Model
|
|
{
|
|
/** @use HasFactory<\Database\Factories\WeeklyReviewFactory> */
|
|
use HasFactory, HasUlids;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'nutrition_plan_id',
|
|
'period_start',
|
|
'period_end',
|
|
'average_calories',
|
|
'average_proteins',
|
|
'average_carbs',
|
|
'average_fats',
|
|
'logged_days_count',
|
|
'weight_entries_count',
|
|
'weight_trend_kg',
|
|
'target_weight_trend_kg',
|
|
'status',
|
|
'recommended_calorie_adjustment',
|
|
'message_code',
|
|
'metrics',
|
|
'generated_at',
|
|
'accepted_at',
|
|
'accepted_nutrition_plan_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'period_start' => 'immutable_date',
|
|
'period_end' => 'immutable_date',
|
|
'average_calories' => 'float',
|
|
'average_proteins' => 'float',
|
|
'average_carbs' => 'float',
|
|
'average_fats' => 'float',
|
|
'logged_days_count' => 'integer',
|
|
'weight_entries_count' => 'integer',
|
|
'weight_trend_kg' => 'float',
|
|
'target_weight_trend_kg' => 'float',
|
|
'status' => WeeklyReviewStatus::class,
|
|
'recommended_calorie_adjustment' => 'integer',
|
|
'metrics' => 'array',
|
|
'generated_at' => 'immutable_datetime',
|
|
'accepted_at' => 'immutable_datetime',
|
|
];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function nutritionPlan(): BelongsTo
|
|
{
|
|
return $this->belongsTo(NutritionPlan::class);
|
|
}
|
|
|
|
public function acceptedNutritionPlan(): BelongsTo
|
|
{
|
|
return $this->belongsTo(NutritionPlan::class, 'accepted_nutrition_plan_id');
|
|
}
|
|
}
|