<?php

namespace App\Imports;

use App\EmployeeTest;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithValidation;
use Maatwebsite\Excel\Concerns\WithBatchInserts;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

class Employee_detailsImport implements ToModel, WithHeadingRow, WithBatchInserts, WithChunkReading, WithValidation

{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    //
   
    public function model(array $row)
    {
        return new EmployeeTest([
           
           'FirstName'          => $row['firstname'],
           'LastName'           => $row['lastname'],
           'Email'              => $row['email'],
           'Gender'             => $row['gender'],
           'DateofJoining'      => Date::excelToDateTimeObject($row['dateofjoining']),
           'YearsofExperience'  => $row['yearsofexperience'],
           
        ]);
    }
    public function batchSize(): int
    {
        return 250;
    }
    public function chunkSize(): int
    {
        return 250;
    }
     public function rules(): array
    {
        return [
            '*.firstname'             => 'required|string',
            '*.lastname'              => 'required|string',             
            '*.email'                 => 'required|email|distinct',
            '*.gender'                => 'required|string',
            '*.dateofjoining'         => 'required', 
            '*.yearsofexperience'     => 'required|numeric',            
        ];       
    }              
}
