<?php

namespace Lc\CaracoleBundle\Definition\Field\Ticket;

use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use Lc\CaracoleBundle\Definition\Field\FieldDefinitionTrait;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Solver\Ticket\TicketSolver;
use Lc\SovBundle\Definition\Field\Ticket\TicketFieldDefinition as SovTicketFieldDefinition;
use Lc\SovBundle\Translation\TranslatorAdmin;

class TicketFieldDefinition extends SovTicketFieldDefinition
{
    use FieldDefinitionTrait;

    protected SectionStore $sectionStore;

    public function __construct(
            TranslatorAdmin $translatorAdmin,
            TicketSolver $ticketSolver,
            SectionStore $sectionStore
    ) {
        parent::__construct($translatorAdmin, $ticketSolver);
        $this->sectionStore = $sectionStore;
    }

    public function configureFields(): array
    {
        return array_merge(parent::configureFields(), [
                'type' => ChoiceField::new('type')
                        ->autocomplete()
                        ->setSortable(true)
                        ->setChoices(
                                $this->translatorAdmin->transChoices(
                                        TicketSolver::getTypeChoices(),
                                        'Ticket',
                                        'type'
                                )
                        ),
        ]);
    }
    public function configureIndex(): array
    {
        return $this->addSectionToFieldArrayIfOutOfSection($this->section, parent::configureIndex());
    }

    public function configureForm(): array
    {
        return array_merge(['section'], parent::configureForm());
    }
}