<?php

namespace App\Models;

use CodeIgniter\Model;

class UserModel extends Model
{
    protected $table            = 'users';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $protectFields    = true;
    protected $allowedFields    = [
        'email',
        'profile_name',
        'age_group',
        'gender',
        'occupation',
        'phone',
        'profile_onboarding_completed',
        'is_active',
        'last_login_at',
    ];
    protected $useTimestamps = true;
    protected $dateFormat    = 'datetime';
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';

    protected $validationRules = [
        'email' => 'required|valid_email|max_length[190]',
    ];

    public function findByEmail(string $email): ?array
    {
        $row = $this->where('email', $email)->first();

        return $row === null ? null : $row;
    }
}
