<?php

namespace App\Imports;

use App\Models\Quiz;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithGroupedHeadingRow;

class QuizImport implements ToModel, WithHeadingRow, WithGroupedHeadingRow
{
    /**
     * @param array $row
     *
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function model(array $row)
    {
        return new Quiz([
            "jenjang" => $row["jenjang"],
            "jenis" => $row["jenis"],
            "soal" => $row["soal"],
            "jawaban" => join("|", $row["jawaban"]),
            "jawaban_benar" => $row["jawaban"][0]
        ]);
    }
}
