<?php

namespace App\Controller\Admin;

use App\Entity\Customer;
use App\Entity\Ticket;
use App\Enum\FoodData;
use App\Enum\TicketData;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;

class TicketCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Ticket::class;
    }

    public function configureFields(string $pageName): iterable
    {
        yield ChoiceField::new('type', 'Typ')
            ->setChoices(TicketData::TYPES);

        yield ChoiceField::new('foodType', 'Ernährung')
            ->setChoices(FoodData::TYPES);

        yield AssociationField::new('customer', 'Käufer')
            ->setCrudController(CustomerCrudController::class)
            ->formatValue(fn(Customer $customer) => $customer->getFirstname(). ' ' . $customer->getLastname())
            ->hideOnForm();

        yield BooleanField::new('checkedIn', '')
            ->setTemplatePath('admin/checked_in.html.twig');
    }


    public function configureActions(Actions $actions): Actions
    {
        return $actions
            ->add(Crud::PAGE_INDEX, Action::DETAIL)
            ->disable(Action::DELETE)
            ->disable(Action::NEW)
            ->setPermission(Action::EDIT, 'ROLE_SUPER_ADMIN');
    }

    public function configureCrud(Crud $crud): Crud
    {
        return $crud
            ->setPageTitle(Crud::PAGE_INDEX, 'Tickets')
            ->setPageTitle(Crud::PAGE_DETAIL, 'Ticket')
            ->showEntityActionsInlined();
    }
}
