<?php

namespace App\Http\Controllers\Migration;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


use App\Models\Department;
use App\Models\Mongo;

class UserController extends Controller
{

    public function index(){

        $tb_scope = DB::table('tb_scope')->get();
        foreach ($tb_scope as $data) {

            $val["id"]              = $data->id;
            $val["user_department"] = array("GI");
            $val["user_status"]     = 'active';
            // $val["comname"]         = $data->comname;
            // $val["tablename"]       = $data->tablename;
            $val["user_code"]       = $data->user_code;
            $val["user_type"]       = $data->user_type;
            $val["user_branch"]     = $data->user_branch;
            $val["practical"]       = $data->practical;
            $val["color"]           = $data->color;
            $val["name"]            = $data->name;
            $val["user_rfid"]       = $data->user_rfid;
            $val["user_prefix"]     = $data->user_prefix;
            $val["user_firstname"]  = $data->user_firstname;
            $val["user_lastname"]   = $data->user_lastname;
            $val["user_email"]      = $data->user_email;
            $val["user_config"]     = $data->user_config;
            $val["email"]           = $data->email;
            $val["password"]        = $data->password;
            $val["remember_token"]  = $data->remember_token;
            $val["opencase"]        = $data->opencase;
            $val["procedure_json"]  = $data->procedure_json;
            $val["created_at"]      = $data->created_at;
            $val["department"]      = 'GI';
            $val["updated_at"]      = $data->updated_at;


            $newuser = Mongo::table("users")
            ->where('user_firstname' , $data->user_firstname)
            ->where('user_lastname' , $data->user_lastname)
            ->first();

            if($newuser){
                Mongo::table("users")
                ->where('user_firstname' , $data->user_firstname)
                ->where('user_lastname' , $data->user_lastname)
                ->update($val);
            }else{
                Mongo::table("users")->insert($val);
            }



            # code...
        }

    }


    public function show($id){
    }

    public function create(){
        $tb_scope = Mongo::table("tb_scope")->get();

        dd($tb_scope);
    }



}
