<?php

namespace App\Imports;

use Carbon\Carbon;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\SkipsOnError;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithBatchInserts;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\RemembersRowNumber;

class CourseImport implements ToModel, SkipsOnError, WithHeadingRow, WithChunkReading, WithBatchInserts
{
    use Importable, RemembersRowNumber;
    private $imported_list = [];

    public function model(array $row){
        $insertArray = [
            'name' => $row['coursename'],
            'institute' => $row['university'],
            'campuses' => $row['campus'],
            'level' => $row['level'],
            'department' => $row['department'],
            'length' => $row['courselength'],
            'intakes' => $row['intake'],
            'toefl' => $row['toefl'],
            'ielts' => $row['ielts'],
            'duolingo' => $row['duolingo'],
            'pte' => $row['pte'],
            'tuitionfee' => $row['tuitionfee'],
            'scholarship' => $row['scholarship'],
            'depositrequired' => $row['depositrequired'],
            'reference' => $row['reference'],
            'sop' => $row['sop'],
            'cv' => $row['cv'],
            'entryrequirement' => $row['entryrequirement'],
            'tags' => $row['tags'],
        ];

        array_push($this->imported_list, $insertArray);
                                            
    }

    public function getImportedRows()
    {
        return $this->imported_list;
    }

    public function onError(\Throwable $e)
    {
        return res_msg('File import failed!', 403);
    }

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

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