<?php
namespace App\Model\Table;

use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * ReportFormatVariables Model

 * @method \App\Model\Entity\ReportFormatVariable get($primaryKey, $options = [])
 * @method \App\Model\Entity\ReportFormatVariable newEntity($data = null, array $options = [])
 * @method \App\Model\Entity\ReportFormatVariable[] newEntities(array $data, array $options = [])
 * @method \App\Model\Entity\ReportFormatVariable|false save(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\ReportFormatVariable saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\ReportFormatVariable patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method \App\Model\Entity\ReportFormatVariable[] patchEntities($entities, array $data, array $options = [])
 * @method \App\Model\Entity\ReportFormatVariable findOrCreate($search, callable $callback = null, $options = [])
 */
class ReportFormatVariablesTable extends Table
{
    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('report_format_variables');
        $this->setPrimaryKey('id');

        $this->belongsTo('ReportFormats');

    }

    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmptyString('id', null, 'create');

        $validator
            ->integer('report_format_id')
            ->requirePresence('report_format_id', 'create')
            ->notEmptyString('report_format_id');

        $validator
            ->scalar('variable_name')
            ->maxLength('variable_name', 100)
            ->requirePresence('variable_name', 'create')
            ->notEmptyString('variable_name')
            ->add('variable_name', 'unique', [
                'rule' => 'validateUnique',
                'provider' => 'table',
                'message' => 'This variable name is already taken.'
            ]);;

        $validator
            ->scalar('table_name')
            ->maxLength('table_name', 100)
            ->requirePresence('table_name', 'create')
            ->notEmptyString('table_name');

        $validator
            ->scalar('column_name')
            ->maxLength('column_name', 100)
            ->requirePresence('column_name', 'create')
            ->notEmptyString('column_name');

        $validator
            ->scalar('data_type')
            ->requirePresence('data_type', 'create')
            ->notEmptyString('data_type');

        $validator
            ->integer('is_mandatory');

        $validator
            ->integer('status');

        $validator
            ->integer('created_by_id')
            ->allowEmptyString('created_by_id');

        $validator
            ->integer('updated_by_id')
            ->allowEmptyString('updated_by_id');

        $validator
            ->dateTime('created_at')
            ->allowEmptyDateTime('created_at');

        $validator
            ->dateTime('updated_at')
            ->allowEmptyDateTime('updated_at');

        return $validator;
    }
}
