<?php

namespace App\Services\PlanDigitizer;

/** Segments of the plan that share one layer and one colour. */
class SegmentGroup
{
    public const ROLE_DIVIDER = 'divider';

    public const ROLE_STRUCTURE = 'structure';

    public const ROLE_STATUS = 'status';

    public const ROLE_TEXT = 'text';

    public const ROLE_TEXTURE = 'texture';

    /** @param list<int> $indexes */
    public function __construct(
        public readonly string $layer,
        public readonly string $color,
        public array $indexes,
        public float $totalLength = 0.0,
        public string $role = self::ROLE_STRUCTURE,
        public ?string $status = null,
    ) {}

    public function count(): int
    {
        return count($this->indexes);
    }

    public function averageLength(): float
    {
        return $this->count() === 0 ? 0.0 : $this->totalLength / $this->count();
    }

    public function key(): string
    {
        return $this->layer.'|'.$this->color;
    }
}
