<?php

class Signupmodel extends CI_Model {

    public function __construct() {

        parent::__construct();
    }

    public function userRegistration($data) {
        $userTable = [
            'doctor_fname' => $data['FName'],
            'doctor_lname' => $data['LName'],
            'doctor_password' => md5($data['Password']),
            'doctor_mobile' => $data['Mobile'],
            'doctor_email' => $data['Email'],
            'OTP' => $data['OTP'],
        ];
        //echo '<pre>'; print_r($userTable); die;         
        $query = $this->db->insert('doctors', $userTable);
        $insert = $this->db->insert_id();
        return $insert;
    }
    public function submitDoctorHelp($data) {             
        $query = $this->db->insert('doc_help', $data);
        $insert = $this->db->insert_id();
        return $insert;
    }

    public function VerifyOTP($data) {
        $this->db->select('*');
        $this->db->from('doctors d');
        $this->db->where('d.doctor_id', $data['UserId']);
        $this->db->where('d.otp', $data['OTP']);
        $query = $this->db->get();
        return $query->first_row();
    }

    public function Login($data) {
        $this->db->select('doctor_id,doctor_email,doctor_mobile,doctor_fname,profile_image,doctor_address,doctor_lname,doctor_password,u.state_name');
        $this->db->from('doctors u');
        $this->db->where('u.doctor_mobile', $data['Mobile']);
        $this->db->where('u.status', 1);
        $this->db->where('u.doctor_password', md5($data['Password']));
        $query = $this->db->get();
        return $query->first_row();
    }

    public function userDetailsById($data) {

        $this->db->select('doctor_id,doctor_email,doctor_mobile,doctor_fname,profile_image,doctor_address,doctor_lname,doctor_password,u.state_name');
        $this->db->from('doctors u');
        $this->db->where('u.doctor_id', $data['UserId']);
        $query = $this->db->get();
        return $query->first_row();
    }

    public function checkMobileExist($data) {
        $this->db->select('doctor_id,status');
        $this->db->from('doctors u');
        $this->db->where('u.doctor_mobile', $data['Mobile']);
        $query = $this->db->get();
        return $query->first_row();
    }

    public function UpdateProfile($data) {
        $arr = array(
            'doctor_fname' => $data['FName'],
            'doctor_lname' => $data['LName'],
            'doctor_email' => $data['Email'], 
            'profile_image' => $data['ProfilePic'],
            'doctor_country' => $data['Country'],
            'doctor_city' => $data['City'],
        );
        print_r($arr);
        $this->db->update('doctors', $arr, array('doctor_id' => $data['UserId']));
        return true;
    }

    public function UpdateDoctor($data,$doctorId) {
        $this->db->update('doctors', $data, array('doctor_id' => $doctorId));
        return true;
    }

}

?>