<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class employeeSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        //set db connection
        DB::connection('old_db');
        $this->reset();
        $employee_list = DB::connection('old_db')->table('vts_users')->get();//\App\Models\Old_db\vts_users::all();

        DB::connection('mysql');
        $this->reset();

        foreach($employee_list as $record){
            \App\Models\Employee::insert([
                'u_id' => $record->u_id,
                'employee_id' => $record->employee_id,
                'firstname' => $record->u_fname,
                'middlename' => $record->u_mname,
                'lastname' => $record->u_lname,
                'position' => $record->u_position,
                'email' => $record->email,
                'mobile' => $record->usr_mobile,
                'mobile_2' => $record->mobileTwo,
                'company_id' => $record->company,
                'dealer_id' => $record->dealer,
                'department_id' => $record->dept_id,
                'enabled' => $record->u_status,
                'date' => $record->date,
                'created_at' => date('Y-m-d h:i:s')
            ]);
        }
    }

    public function reset()
    {
        \App\Models\Employee::truncate();
    }
}
