<?php

namespace App\Imports;

use App\Models\Mark;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\ToModel;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
// use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithStartRow;
use Illuminate\Contracts\Queue\ShouldQueue;

class BulkMarkImport implements ToCollection
{
    /**
    * @param Collection $collection
    */

    private $data; 

    public function __construct(array $data = [])
    {
        $this->teacher_id = $data['teacher_id'];
    }

    public function collection(collection $rows)
    {
        foreach ($rows as $key => $value) {
            // dd($value);
            if($value[0] == "Sudent Name" || $value[1] == "Exam Type")
            {
                
            }
            else
            {
                // dd($value);
                $user_details        = User::where('name', $value[0])->first();
                
                $mark                = new Mark();
                $mark->student_id    = $user_details->id;
                $mark->teacher_id    = $this->teacher_id;
                $mark->exam_type     = $value[1];
                $mark->paper_1       = $value[2];
                $mark->paper_2       = $value[3];
                $mark->paper_3       = $value[4];
                $mark->paper_4       = $value[5];
                $mark->paper_5       = $value[6];
                $mark->grade         = $value[7];
                $mark->save();
                
            }
        }
    }
}
