$this->id, 'event_id' => $this->event_id, 'name' => $this->name, 'person_type' => $this->person_type, 'date' => $this->date->toDateString(), 'start_time' => Carbon::parse($this->start_time)->format('H:i'), 'end_time' => Carbon::parse($this->end_time)->format('H:i'), 'duration_hours' => $this->duration_hours, 'source' => $this->resource->getAttribute('source'), 'event_name' => $this->whenLoaded('event', fn () => $this->event->name), 'shifts_count' => $this->whenCounted('shifts'), // Aggregates computed from eager-loaded shifts with assignment counts. // For events with >200 shifts, consider replacing with a raw aggregate query. 'total_slots' => $this->when( $this->relationLoaded('shifts'), fn () => (int) $this->shifts->sum('slots_total'), ), 'filled_slots' => $this->when( $this->relationLoaded('shifts'), fn () => (int) $this->shifts->sum(fn ($shift) => $shift->assignments_count ?? 0), ), 'sections_count' => $this->when( $this->relationLoaded('shifts'), fn () => $this->shifts->pluck('festival_section_id')->unique()->count(), ), 'created_at' => $this->created_at->toIso8601String(), ]; } }