<?php

namespace App\Model\Table;


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

class AgentsTable extends Table
{
    public function initialize(array $config): void
    {
        parent::initialize($config);

        $this->setTable('agents');
        $this->setPrimaryKey('id');
        $this->setDisplayField('first_name');
        $this->addBehavior('Timestamp');
    }

    public function validationDefault(Validator $validator): Validator
    {
        $validator
            ->notEmptyString('first_name')
            ->maxLength('first_name', 50)
            ->notEmptyString('last_name')
            ->maxLength('last_name', 50)
            ->notEmptyString('email')
            ->maxLength('email', 100)
            ->email('email')
            ->maxLength('phone_number', 20)
            ->allowEmptyString('phone_number')
            ->maxLength('agency_name', 100)
            ->allowEmptyString('agency_name')
            ->date('hire_date')
            ->allowEmptyDate('hire_date')
            ->maxLength('address', 255)
            ->allowEmptyString('address')
            ->maxLength('country_name', 20)
            ->allowEmptyString('country_name')
            ->inList('status', [0, 1], 'Status must be 0 (inactive) or 1 (active)')
            ->integer('status');

        return $validator;
    }
}