'int', 'restaurant_id' => 'int', 'active' => 'boolean', 'ordering' => 'int', 'settings' => 'json' ]; public static function booted() { static::creating(function($model) { if (empty($model->uuid)) { $model->uuid = Str::uuid('ly'); } }); } // Relationships public function restaurant() { return $this->belongsTo(Restaurant::class); } // Accessors public function getHotspotsAttribute() { $settings = $this->settings ?? []; return $settings['hotspots'] ?? []; } public function getPricingAttribute() { $settings = $this->settings ?? []; return $settings['pricing'] ?? []; } public function getTablesAttribute() { $hotspots = $this->hotspots; if (is_array($hotspots)) { $tables_id = []; foreach($hotspots as $hotspot){ $tables_id[] = $hotspot['id']; } return Table::whereIn('id', $tables_id)->get()->toArrayEachModel(); } return []; } public function getConfigAttribute() { $settings = $this->settings ?? []; return $settings['config'] ?? []; } // Helper methods public function setHotspots($hotspots) { $settings = $this->settings ?? []; $settings['hotspots'] = $hotspots; $this->settings = $settings; return $this; } public function setPricing($pricing) { $settings = $this->settings ?? []; $settings['pricing'] = $pricing; $this->settings = $settings; return $this; } public function setConfig($config) { $settings = $this->settings ?? []; $settings['config'] = $config; $this->settings = $settings; return $this; } public function updateSettings($key, $value) { $settings = $this->settings ?? []; $settings[$key] = $value; $this->settings = $settings; return $this; } /** * Get hotspot by table ID */ public function getHotspotByTableId($tableId) { $hotspots = $this->hotspots; foreach ($hotspots as $hotspot) { if (isset($hotspot['id']) && $hotspot['id'] == $tableId) { return $hotspot; } } return null; } /** * Add or update hotspot */ public function addHotspot($tableId, $x, $y, $description = '', $size = null, $color = null) { $hotspots = $this->hotspots; // Check if hotspot for this table already exists $index = null; foreach ($hotspots as $i => $hotspot) { if (isset($hotspot['id']) && $hotspot['id'] == $tableId) { $index = $i; break; } } $hotspotData = [ 'id' => $tableId, 'position' => [ 'left' => $x, 'top' => $y ], 'description' => $description, 'created_at' => date('Y-m-d H:i:s') ]; // Add size and color if provided if ($size !== null) { $hotspotData['size'] = $size; } if ($color !== null) { $hotspotData['color'] = $color; } if ($index !== null) { // Update existing hotspot $hotspots[$index] = array_merge($hotspots[$index], $hotspotData); $hotspots[$index]['updated_at'] = date('Y-m-d H:i:s'); } else { // Add new hotspot $hotspots[] = $hotspotData; } return $this->setHotspots($hotspots); } /** * Remove hotspot by table ID */ public function removeHotspot($tableId) { $hotspots = $this->hotspots; $hotspots = array_filter($hotspots, function($hotspot) use ($tableId) { return !isset($hotspot['id']) || $hotspot['id'] != $tableId; }); return $this->setHotspots(array_values($hotspots)); } /** * Add or update pricing for tag */ public function addPricing($tagId, $price, $currency = 'EUR') { $pricing = $this->pricing; $pricing[$tagId] = [ 'tag_id' => $tagId, 'price' => $price, 'currency' => $currency, 'updated_at' => date('Y-m-d H:i:s') ]; return $this->setPricing($pricing); } /** * Remove pricing for tag */ public function removePricing($tagId) { $pricing = $this->pricing; unset($pricing[$tagId]); return $this->setPricing($pricing); } /** * Get price for a table based on its tags */ public function getPriceForTable($table) { if (!$table || !isset($table['tagsList'])) { return null; } $pricing = $this->pricing; $tableTags = $table['tagsList']; // Find the first matching tag that has pricing foreach ($tableTags as $tagId) { if (isset($pricing[$tagId])) { return $pricing[$tagId]; } } return null; } /** * Update layout configuration */ public function updateConfig($configData) { $config = $this->config; // Merge new config data with existing $config = array_merge($config, $configData); return $this->setConfig($config); } /** * Get configuration value */ public function getConfigValue($key, $default = null) { $config = $this->config; return $config[$key] ?? $default; } /** * Get hotspot configuration */ public function getHotspotConfig() { $config = $this->config; return [ 'displayStyle' => $config['displayStyle'] ?? 'circle', 'globalSize' => $config['globalSize'] ?? 24, 'globalSizeMobile' => $config['globalSizeMobile'] ?? 18, 'globalColor' => $config['globalColor'] ?? '#ef4444', 'allowIndividualOverrides' => $config['allowIndividualOverrides'] ?? true ]; } /** * Get background configuration */ public function getBackgroundConfig() { $config = $this->config; return [ 'cssFilter' => $config['cssFilter'] ?? '' ]; } }