<?php
namespace App\Model\Table;

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

/**
 * ReportFormats Model

 * @method \App\Model\Entity\ReportFormat get($primaryKey, $options = [])
 * @method \App\Model\Entity\ReportFormat newEntity($data = null, array $options = [])
 * @method \App\Model\Entity\ReportFormat[] newEntities(array $data, array $options = [])
 * @method \App\Model\Entity\ReportFormat|false save(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\ReportFormat saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\ReportFormat patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method \App\Model\Entity\ReportFormat[] patchEntities($entities, array $data, array $options = [])
 * @method \App\Model\Entity\ReportFormat findOrCreate($search, callable $callback = null, $options = [])
 */
class ReportFormatsTable 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_formats');
        $this->setDisplayField('name');
        $this->setPrimaryKey('id');

    }

    /**
     * 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_type_id')
            ->requirePresence('report_format_type_id', 'create')
            ->notEmptyString('report_format_type_id')
            ->add('report_format_type_id', 'unique', [
                'rule' => 'validateUnique',
                'provider' => 'table',
                'message' => 'This report format type  is already taken.'
            ]);

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

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

        $validator
            ->allowEmptyString('file_name');

        $validator
            ->allowEmptyString('file_path');

        $validator
            ->allowEmptyString('language');

        $validator
            ->allowEmptyString('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;
    }
}
