$value) { if (property_exists($availability, $key)) { // Handle boolean conversion if ($key === 'is_blocked' && is_string($value)) { $availability->$key = in_array(strtolower($value), ['1', 'true', 'yes'], true); } elseif ($key === 'id') { $availability->$key = (int) $value; } elseif ($key === 'trip_id') { $availability->$key = (int) $value; } elseif (in_array($key, ['seats_total', 'seats_available', 'seats_reserved', 'seats_waitlist', 'cutoff_hours', 'alert_threshold'], true)) { $availability->$key = (int) $value; } elseif (in_array($key, ['original_price', 'discounted_price', 'discount_percentage'], true)) { $availability->$key = $value !== null ? (float) $value : null; } elseif ($key === 'price_types') { // Handle price_types as JSON if (is_string($value)) { $availability->$key = json_decode($value, true) ?: []; } elseif (is_array($value)) { $availability->$key = $value; } else { $availability->$key = []; } } else { $availability->$key = $value; } } } return $availability; } /** * Convert to array */ public function toArray(): array { return [ 'id' => $this->id, 'trip_id' => $this->trip_id, 'departure_date' => $this->departure_date, 'arrival_date' => $this->arrival_date, 'return_date' => $this->return_date, 'departure_time' => $this->departure_time, 'arrival_time' => $this->arrival_time, 'seats_total' => $this->seats_total, 'seats_available' => $this->seats_available, 'seats_reserved' => $this->seats_reserved, 'seats_waitlist' => $this->seats_waitlist, 'booked_seats' => $this->seats_total - $this->seats_available - $this->seats_reserved, 'total_seats' => $this->seats_total, 'available_seats' => $this->seats_available, 'waitlist_count' => $this->seats_waitlist, 'pricing_type' => $this->pricing_type, 'original_price' => $this->original_price, 'discounted_price' => $this->discounted_price, 'discount_percentage' => $this->discount_percentage, 'price_types' => $this->price_types, 'status' => $this->status, 'from_location' => $this->from_location, 'to_location' => $this->to_location, 'from_latitude' => $this->from_latitude, 'from_longitude' => $this->from_longitude, 'to_latitude' => $this->to_latitude, 'to_longitude' => $this->to_longitude, 'special_notes' => $this->special_notes, 'cutoff_date' => $this->cutoff_date, 'cutoff_hours' => $this->cutoff_hours, 'is_blocked' => $this->is_blocked, 'block_reason' => $this->block_reason, 'alert_threshold' => $this->alert_threshold, 'last_synced_at' => $this->last_synced_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; } }