<?php

namespace App\Controller\Admin;

use App\Entity\Sector;
use App\Enum\SectorStatusEnum;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;

class SectorCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Sector::class;
    }

    public function configureFields(string $pageName): iterable
    {
        return [
            IdField::new('id')->onlyOnIndex(),
            TextField::new('name'),
            ChoiceField::new('status')
                ->setChoices($this->enumChoices(SectorStatusEnum::class))
                ->renderExpanded(false)
                ->renderAsBadges(),
        ];
    }

    /**
     * @param class-string $enumClass
     * @return array<string, string>
     */
    private function enumChoices(string $enumClass): array
    {
        $choices = [];
        foreach ($enumClass::cases() as $case) {
            $choices[$case->name] = $case;
        }
        return $choices;
    }
}
