<?php

namespace ModulesGarden\HostingQuotaNotifications\App\UI\TicketTemplates\Forms;

use ModulesGarden\HostingQuotaNotifications\App\Helper\Models\Admin;
use ModulesGarden\HostingQuotaNotifications\App\UI\Validators\NotEmptyWithTrim;
use ModulesGarden\HostingQuotaNotifications\App\UI\Validators\TicketTemplateExist;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\BaseForm;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Interfaces\AdminArea;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\FormConstants;
use \ModulesGarden\HostingQuotaNotifications\App\UI\TicketTemplates\Providers\TicketTemplatesProvider;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Fields\Text;
use \ModulesGarden\HostingQuotaNotifications\Core\UI\Widget\Forms\Fields\Select;
use \ModulesGarden\HostingQuotaNotifications\App\Helper\Models\TicketDepartment;

/**
 * Description of AddTicketTemplateForm
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class AddTicketTemplateForm extends BaseForm implements AdminArea
{
    protected $id    = 'addTicketTemplateForm';
    protected $name  = 'addTicketTemplateForm';
    protected $title = 'addTicketTemplateForm';

    public function initContent()
    {
        $this->setFormType(FormConstants::CREATE);
        $this->dataProvider = new TicketTemplatesProvider();
        $this->initFields();
    }

    protected function initFields()
    {
        $this->addField((new Text('name'))->addValidator(new NotEmptyWithTrim())->addValidator(new TicketTemplateExist()));
        $this->addField((new Select('department_id'))->notEmpty()->setAvalibleValues(TicketDepartment::getDepartmentsIDkeyNAMEvalue()));

        $field = new Select('admin_id');
        $field->notEmpty();
        $field->setAvalibleValues(Admin::getAdminsAsKeyIdNameValue());
        $this->addField($field);
    }
}
