<?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(),

            'type' => Shm::enum([
                'seat' => 'Место',
                'sector' => 'Сектор',
                'table' => 'Стол',
                'stage' => 'Сцена',
                'wall' => 'Стена',
                'zone' => 'Зона',
            ]),

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

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

        ]);


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

            $parts = [];

            if (isset($item->seat->row)) {
                $parts[] = $item->seat->row . " ряд";
            }

            if (isset($item->seat->number)) {
                $parts[] = $item->seat->number . " место";
            }

            if (isset($item->sector)) {
                $parts[] = $item->sector;
            }

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

        return $schema;
    }
}
