<?php

namespace App\Models;

use CodeIgniter\Model;

class MemberModel extends Model
{
    protected $table          = 'member';
    protected $primaryKey     = 'mb_idx';
    protected $returnType     = 'object';
    protected $useTimestamps  = false;
    protected $allowedFields  = [
        'mb_id',
        'mb_passwd',
        'mb_name',
        'mb_email',
        'mb_phone',
        'mb_lang',
        'mb_level',
        'mb_group',
        'mb_lg_idx',
        'mb_state',
        'mb_regdate',
        'mb_latestdate',
        'mb_leavedate',
        'mb_login_fail_count',
        'mb_locked_until',
    ];

    /**
     * mb_id로 회원 조회
     */
    public function findByLoginId(string $mbId): ?object
    {
        return $this->where('mb_id', $mbId)->first();
    }

    /**
     * mb_id 중복 여부
     */
    public function isIdExists(string $mbId): bool
    {
        return $this->where('mb_id', $mbId)->countAllResults() > 0;
    }
}
