<?php
namespace App\Model\Table;

use Cake\ORM\Table;
use Cake\Validation\Validator;
/**
 * LetterSentHistory Model

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

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



        $this->belongsTo('ReportFormats', [
            'foreignKey' => 'report_format_id',
            'joinType' => 'LEFT',
        ]);
        $this->belongsTo('ReportFormatTypes', [
            'foreignKey' => 'report_type_id',
            'joinType' => 'LEFT',
        ]);

        $this->belongsTo('Students', [
            'foreignKey' => 'student_id',
            'joinType' => 'LEFT',
        ]);


    }
    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->notEmptyString('report_type_id')
            ->notEmptyString('student_id')
            ->notEmptyString('student_email')
            ->notEmptyDate('sent_date');

        return $validator;
    }
}
