<?php
declare(strict_types=1);

namespace App\Model\Table;

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

/**
 * SlowQueries Model
 *
 * @method \App\Model\Entity\SlowQuery newEmptyEntity()
 * @method \App\Model\Entity\SlowQuery newEntity(array $data, array $options = [])
 * @method \App\Model\Entity\SlowQuery[] newEntities(array $data, array $options = [])
 * @method \App\Model\Entity\SlowQuery get($primaryKey, $options = [])
 * @method \App\Model\Entity\SlowQuery findOrCreate($search, ?callable $callback = null, $options = [])
 * @method \App\Model\Entity\SlowQuery patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method \App\Model\Entity\SlowQuery[] patchEntities(iterable $entities, array $data, array $options = [])
 * @method \App\Model\Entity\SlowQuery|false save(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\SlowQuery saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\SlowQuery[]|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, $options = [])
 * @method \App\Model\Entity\SlowQuery[]|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, $options = [])
 * @method \App\Model\Entity\SlowQuery[]|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, $options = [])
 * @method \App\Model\Entity\SlowQuery[]|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, $options = [])
 *
 * @mixin \Cake\ORM\Behavior\TimestampBehavior
 */
class SlowQueriesTable extends Table
{
    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config): void
    {
        parent::initialize($config);

        $this->setTable('slow_queries');
        $this->setDisplayField('id');
        $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
    {
        $validator
            ->integer('id')
            ->allowEmptyString('id', null, 'create');

        $validator
            ->scalar('user')
            ->maxLength('user', 255)
            ->allowEmptyString('user');

        $validator
            ->scalar('schema')
            ->maxLength('schema', 255)
            ->allowEmptyString('schema');

        $validator
            ->scalar('query_time')
            ->maxLength('query_time', 20)
            ->allowEmptyString('query_time');

        $validator
            ->scalar('lock_time')
            ->maxLength('lock_time', 20)
            ->allowEmptyString('lock_time');

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

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

        $validator
            ->scalar('date')
            ->maxLength('date', 20)
            ->allowEmptyString('date');

        $validator
            ->scalar('query')
            ->allowEmptyString('query');

        return $validator;
    }
}
