<?php

namespace Shm\ShmAddons\EventTicketAddon\Types\HallType;

use Shm\Collection\Collection;
use Shm\Shm;
use Shm\ShmTypes\StructureType;

class HallElements extends Collection
{

    public function schema(): StructureType
    {
        $schema = Shm::structure([



            'hallUUID' => Shm::string(),
            'x' =>  Shm::nonNull(Shm::float()),
            'y' =>  Shm::nonNull(Shm::float()),
            'width' =>  Shm::float(),
            'height' =>  Shm::float(),
            'rotation' =>  Shm::float(),
            'label' => Shm::string(),
            'points' => Shm::arrayOf(Shm::number()),

            'type' => Shm::enum([
                'seat' => 'Место',
                'sector' => 'Сектор',
                'table' => 'Стол',
                'stage' => 'Сцена',
                'wall' => 'Стена',
                'zone' => 'Зона',
                'sector_polygon' => "Сектор (сводобной формы)",
                'canvas' => "Поверхность для рисования"
            ]),

            'seat' => Shm::structure([
                'number' => Shm::string(),
                'row' => Shm::string(),
            ]),

            'sector' =>  HallElements::ID(),

        ]);


        $schema->setDisplayFunc(function ($item) {

            $parts = [];

            $row = HallElementsField::SEAT__ROW_GET($item);
            if ($row) {
                $parts[] = $row . " ряд";
            }

            $number = HallElementsField::SEAT__NUMBER_GET($item);
            if ($number) {
                $parts[] = $number . " место";
            }

            $sector = HallElementsField::SECTOR_GET($item);
            if ($sector) {
                $parts[] = $sector;
            }

            return implode(", ", $parts) ?? "Без места";
        });

        return $schema;
    }
}
