<?php

namespace App\Imports;

use App\Result;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithBatchInserts;
use Maatwebsite\Excel\Concerns\WithChunkReading;

class ResultsImport implements ToCollection, WithHeadingRow, WithBatchInserts, WithChunkReading
{
    /**
     * @param array $row
     *
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function collection(Collection $rows)
    {
 
        foreach ($rows as $row) {
            Result::create([
                'matric' => $row['matric'],
                'session' => $row['session'],
                'semester' => $row['semester'],
                'course_code' => $row['course_code'],
                    'stud_id' => $row['stud_id'],
                    'name' => $row['name'],
                    'title' => $row['title'],
                    'unit' => $row['unit'],
                    'score' => $row['score'],
                    'grade' => $row['grade']=='?'?'?':$row['grade'],
                    'point' => $row['point'],
                    'level' => $row['level'],
                    'remark' => $row['remark'],
                    'carry_over' => $row['carry_over'],
                    'current_tcue' => $row['current_tcue'],
                    'current_tcur' => $row['current_tcur'],
                    'current_tcp' => $row['current_tcp'],
                    'previous_tcue' => $row['previous_tcue'],
                    'previous_tcur' => $row['previous_tcur'],
                    'previous_tcp' => $row['previous_tcp'],
                    'degree_name' => $row['degree_name'],
                    'department_name' => $row['department_name'],
                ]);
        }
      
    }

    public function batchSize(): int
    {
        return 500;
    }

    public function chunkSize(): int
    {
        return 500;
    }

}
