'decimal:2', 'daily_limit' => 'decimal:2', 'current_month_spending' => 'decimal:2', 'current_day_spending' => 'decimal:2', 'month_started_at' => 'date', 'day_started_at' => 'date', 'alert_threshold_percentage' => 'integer', 'last_alert_sent_at' => 'datetime', 'is_budget_exceeded' => 'boolean', 'is_active' => 'boolean', ]; public function user(): BelongsTo { return $this->belongsTo(User::class); } public function getRemainingMonthlyBudget(): float { return max(0, $this->monthly_limit - $this->current_month_spending); } public function getRemainingDailyBudget(): ?float { if (!$this->daily_limit) { return null; } return max(0, $this->daily_limit - $this->current_day_spending); } public function getMonthlyUsagePercentage(): float { if ($this->monthly_limit == 0) { return 0; } return ($this->current_month_spending / $this->monthly_limit) * 100; } public function shouldSendAlert(): bool { $percentage = $this->getMonthlyUsagePercentage(); return $percentage >= $this->alert_threshold_percentage && (!$this->last_alert_sent_at || $this->last_alert_sent_at->lt(now()->subHours(24))); } }