<?php

namespace App\Controller\Admin;

use App\Entity\Projects;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;

class ProjectsCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Projects::class;
    }

    public function configureFields(string $pageName): iterable
    {
        yield IdField::new(propertyName: 'id')
            ->onlyOnIndex();
        yield TextField::new(propertyName: 'name');
        yield AssociationField::new('developer');
        yield TextField::new(propertyName: 'description');
        yield ImageField::new(propertyName: 'teaserImage')
            ->setBasePath(path: 'uploads/projects')
            ->setUploadDir(uploadDirPath: 'public/uploads/projects')
            ->setUploadedFileNamePattern(patternOrCallable: '[timestamp]-[slug].[extension]');
        yield Field::new('createdAt')
            ->hideOnForm();
    }
}
