'decimal:2', 'max_purchase_amount' => 'decimal:2', 'discount_percentage' => 'decimal:2', 'is_active' => 'boolean', ]; /** * Clientes que pertenecen a este nivel */ public function clients(): HasMany { return $this->hasMany(Client::class, 'tier_id'); } /** * Niveles nuevos en el historial */ public function tierHistories(): HasMany { return $this->hasMany(ClientTierHistory::class, 'new_tier_id'); } /** * Niveles antiguos en el historial */ public function oldTierHistories(): HasMany { return $this->hasMany(ClientTierHistory::class, 'old_tier_id'); } /** * Alcance de consulta para niveles activos */ public function scopeActive($query) { return $query->where('is_active', true); } /** * Verifica si un monto de compra califica para este nivel */ public function qualifies(float $amount): bool { if (!$this->is_active) { return false; } if ($amount < $this->min_purchase_amount) { return false; } if ($this->max_purchase_amount !== null && $amount > $this->max_purchase_amount) { return false; } return true; } }