<?php

namespace App\Models;

use CodeIgniter\Model;
use CodeIgniter\I18n\Time;

class Md_login extends Model {
    
    public $db;

    public function __construct() {
        parent::__construct();
        $this->services = \Config\Database::connect('services');
    }
    
    
 public function loginUserVerify($username,$password,$module) {

        $notifications = $this->services
                ->table('users')
                ->select('pk_user_id,usr_fullname,usr_email,usr_mobileno,module')
                ->where('usr_username', $username)
                ->where('usr_password', $password)
                ->where('module', $module)
                ->where('usr_status','1')
                ->limit(1)
                ->get()
                ->getRow();
                
                if(!empty($notifications))
                {
                    $roles= $this->services
                    ->table('user_privilege')
                    ->select('privilage')
                    ->where('fk_uid', $notifications->pk_user_id)
                    ->limit(1)
                    ->get()
                    ->getRow();
                    
                    $notifications->roles=(!empty($roles)?$roles->privilage:null);
                }
           
        return $notifications;
    }
    
  public function OTPVerifyCheck($Mobile) {

        $notifications = $this->db
                ->table('otp_verify')
                ->where('mobile', $Mobile)
                ->where('verify', 1)
                ->limit(1)
                ->get()
                ->getRow();
        return $notifications;
    }

   public function UpdateData($table, $pk_id, $data = array()) {
        $this->services
                ->table($table)
                ->update($data, $pk_id);
        return true;
    }

}