<?php

namespace App\Models;

class UserModel extends BaseModel
{
    protected $table      = 'users';
    protected $primaryKey = 'id';

    protected $allowedFields = [
        'uuid', 'church_id', 'role_id', 'name', 'email',
        'password_hash', 'phone', 'is_active', 'last_login_at',
    ];

    protected $validationRules = [
        'name'  => 'required|min_length[2]|max_length[255]',
        'email' => 'required|valid_email',
    ];

    public function findByEmail(string $email, int $churchId): ?array
    {
        return $this->where('email', $email)
                    ->where('church_id', $churchId)
                    ->where('deleted_at IS NULL')
                    ->first();
    }
}
