*/ public function toArray(Request $request): array { $fields = match ($this->type) { ValidityTimeType::TimeWindow => [ 'start_time' => $this->start_time, 'end_time' => $this->end_time, ], ValidityTimeType::FixedWindow => [ 'fixed_starts_at' => $this->fixed_starts_at, 'fixed_expires_at' => $this->fixed_expires_at, ], }; return [ 'id' => $this->id, 'type' => $this->type->value, 'is_valid' => $this->isValid(), ...array_filter($fields, fn (mixed $value): bool => $value !== null), ]; } }