<?php

namespace App\Models;

use CodeIgniter\Model;

class UsuarioModel extends Model
{
    protected $table            = 'usuario';
    protected $primaryKey       = 'id_usuario';
    protected $useAutoIncrement = true;
    protected $returnType       = 'App\Entities\Usuario';
    protected $useSoftDeletes   = false;
    protected $protectFields    = true;
    protected $allowedFields    = [
        'id_rol',
        'nombres',
        'apellidos',
        'email',
        'password',
        'telefono',
        'estado'
    ];

    // Dates
    protected $useTimestamps = false;
    protected $dateFormat    = 'datetime';
    protected $createdField  = 'created_at';

    // Validation
    protected $validationRules      = [
        'id_rol'    => 'required|integer',
        'nombres'   => 'required|min_length[2]|max_length[100]',
        'apellidos' => 'required|min_length[2]|max_length[100]',
        'email'     => 'required|valid_email|is_unique[usuario.email,id_usuario,{id_usuario}]',
        'password'  => 'required|min_length[6]',
    ];
    protected $validationMessages   = [
        'email' => [
            'is_unique' => 'El correo electrónico ya está registrado.',
            'valid_email' => 'Por favor, ingrese un correo electrónico válido.'
        ]
    ];
    protected $skipValidation       = false;
    protected $cleanValidationRules = true;
}
