*/ protected function casts(): array { return ['version' => 'integer', 'condition_id' => 'integer']; } public function label(): string { return $this->name.' (Version '.$this->version.')'; } /** * Whether this annex belongs to the booking by its condition (manual annexes are only added by hand). */ public function appliesTo(Booking $booking): bool { $channelId = $booking->import_channel_id ?? $booking->origin_channel_id; return match ($this->condition_type) { self::ALWAYS => true, self::EXTRA => $this->condition_id !== null && (int) ($booking->extras[$this->condition_id] ?? 0) > 0, self::CHANNEL => $this->condition_id !== null && (int) $channelId === $this->condition_id, default => false, }; } public function isUsed(): bool { return Booking::query()->whereJsonContains('offer_terms->annex_ids', $this->id)->exists(); } public function newVersion(): self { $latest = static::query()->where('name', $this->name)->max('version'); return static::query()->create([ 'name' => $this->name, 'version' => $latest + 1, 'title' => $this->title, 'body' => $this->body, 'condition_type' => $this->condition_type, 'condition_id' => $this->condition_id, 'notes' => $this->notes, ]); } }