<?php

namespace OfficeBrain\Bundle\QuickQuoteBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints as Assert;

class QuickQuoteType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('toEmail', 'text', array(
                    'required'=>false,
                    'constraints' => array(
                    new Assert\NotBlank(array('message' => 'quick_quote.to_email.not_blank')),
                    new Assert\Regex(array(
                    'pattern' => '/^[a-zA-Z0-9_\.\+\-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+$/',
                    'message' => 'quick_quote.to_email.invalid',
                    ))
            )))
            ->add('fromName', 'text', array(
                    'required'=>false,
                    'constraints' => array(new Assert\NotBlank(array('message' => 'quick_quote.from_name.not_blank')),
            )))
            ->add('toName', 'text', array(
            		'required'=>false,
            		'constraints' => array(new Assert\NotBlank(array('message' => 'quick_quote.to_name.not_blank')),
            		)))
            
            ->add('fromEmail', 'text', array(
                    'required'=>false,
                    'constraints' => array(
                    new Assert\NotBlank(array('message' => 'quick_quote.from_email.not_blank')),
                    new Assert\Regex(array(
                        'pattern' => '/^[a-zA-Z0-9_\.\+\-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+$/',
                        'message' => 'quick_quote.from_email.invalid',
                    ))
            )))
            ->add('message', 'textarea', array(
                    'required'=>false,
                    'constraints' => array(new Assert\NotBlank(array('message' => 'quick_quote.message.not_blank')),
            )))
        ;
    }
   
    
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'OfficeBrain\Bundle\QuickQuoteBundle\Entity\QuickQuote'
        ));
    }
    
    /**
     * @return string
     */
    public function getName()
    {
        return 'quick_quote';
    }
}
