<?php

namespace App\Appointment\Plan\ValueObject;

final readonly class PlannedSegment
{
    /** @param list<PlannedRequirement> $requirements */
    public function __construct(
        public int $sequence,
        public string $name,
        public int $offsetMinutes,
        public int $durationMinutes,
        public bool $patientPresent,
        public bool $mergeable,
        public array $requirements,
    ) {}

    public function toArray(): array
    {
        return [
            'sequence'         => $this->sequence,
            'name'             => $this->name,
            'offset_minutes'   => $this->offsetMinutes,
            'duration_minutes' => $this->durationMinutes,
            'patient_present'  => $this->patientPresent,
            'mergeable'        => $this->mergeable,
            'requirements'     => array_map(
                static fn (PlannedRequirement $r): array => $r->toArray(),
                $this->requirements,
            ),
        ];
    }
}
