<?php

namespace RxConnexionBundle\Form\Type;

use RxConnexionBundle\Entity\InventoryEntity;
use RxConnexionBundle\Entity\InventorySerialNoEntity;
use RxConnexionBundle\Entity\PatientBillingEntity;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Doctrine\Common\Persistence\ObjectManager;
use RxConnexionBundle\Form\DataTransformer\DataTransformer;

class PatientBillingInventoryForm extends AbstractType
{
    private $manager;

    public function __construct(ObjectManager $manager) {
        $this->manager = $manager;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('id', HiddenType::class, array(
                'required' => false
            ))
            ->add('serial_no', TextType::class, array(
                'required' => false
            ))
            ->add('quantity', TextType::class, array(
                'required' => false
            ))
            ->add('inventory_serial_no', TextType::class, array(
                'required' => false
            ))
            ->add('patient_billing', HiddenType::class, array(
                'required' => false
            ))
            ->add('item', HiddenType::class, array(
                'required' => false
            ))
            ->add('item_description', HiddenType::class, array(
                'required' => false,
                'mapped' => false,
            ))
            ->add('inventory_description', HiddenType::class, array(
                'required' => false,
                'mapped' => false,
            ))
            ->add('inventory', HiddenType::class, array(
                'required' => false
            ))
        ;

        $builder->get('item')->addModelTransformer(new DataTransformer($this->manager, 'RxConnexionBundle:ItemEntity', false));
        $builder->get('inventory_serial_no')->addModelTransformer(new DataTransformer($this->manager, InventorySerialNoEntity::class, false));
        $builder->get('patient_billing')->addModelTransformer(new DataTransformer($this->manager, PatientBillingEntity::class, false));
        $builder->get('inventory')->addModelTransformer(new DataTransformer($this->manager, InventoryEntity::class, false));
    }

    public function getBlockPrefix()
    {
        return 'patientBillingInventory';
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'RxConnexionBundle\Entity\PatientBillingInventoryEntity'
        ));
    }
}