<?php
namespace App\Model\Table;

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

/**
 * Usfails Model
 *
 * @method \App\Model\Entity\Usfail get($primaryKey, $options = [])
 * @method \App\Model\Entity\Usfail newEntity($data = null, array $options = [])
 * @method \App\Model\Entity\Usfail[] newEntities(array $data, array $options = [])
 * @method \App\Model\Entity\Usfail|bool save(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\Usfail patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method \App\Model\Entity\Usfail[] patchEntities($entities, array $data, array $options = [])
 * @method \App\Model\Entity\Usfail findOrCreate($search, callable $callback = null, $options = [])
 *
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
 */
class UsfailsTable extends Table
{

    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('usfails');
        $this->setDisplayField('name');
        $this->setPrimaryKey('id');

        $this->addBehavior('Timestamp');
    }

    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create', 'schluessel', 'sst_objekt', 'fehler_kurz', 'fehler_lang', 'korrekturhinweis', 'ref_feld');

        $validator
            ->scalar('snr')
            ->maxLength('snr', 4)
            ->requirePresence('snr', 'create')
            ->notEmpty('snr');

        $validator
            ->scalar('name')
            ->maxLength('name', 50)
            ->requirePresence('name', 'create')
            ->notEmpty('name');

        $validator
            ->scalar('status')
            ->maxLength('status', 50)
            ->requirePresence('status', 'create')
            ->notEmpty('status');

        $validator
            ->dateTime('lieferdatum')
            ->requirePresence('lieferdatum', 'create')
            ->notEmpty('lieferdatum');

        $validator
            ->scalar('lieferung')
            ->maxLength('lieferung', 20)
            ->requirePresence('lieferung', 'create')
            ->notEmpty('lieferung');

        $validator
            ->scalar('auftrag')
            ->maxLength('auftrag', 20)
            ->requirePresence('auftrag', 'create')
            ->notEmpty('auftrag');

        $validator
            ->boolean('plausi')
            ->requirePresence('plausi', 'create')
            ->notEmpty('plausi');

        return $validator;
    }
}
