<?php

namespace App\Imports;

use App\Models\Santri;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class SantrisImport implements ToModel, WithHeadingRow
{
    public function model(array $row)
    {
        $user = User::create([
            'name' => $row['nama'],
            'username' => $row['nis'], // atau kolom username dari excel
            'password' => Hash::make($row['nis']), // default password NIS
            'role' => 'santri',
            'status' => 'aktif',
        ]);

        return new Santri([
            'user_id' => $user->id,
            'nama' => $row['nama'],
            'nis' => $row['nis'],
            'kelas_id' => $row['kelas_id'],
            'alamat' => $row['alamat'],
            'tanggal_lahir' => $row['tanggal_lahir'],
            'jenis_kelamin' => $row['jenis_kelamin'],
        ]);
    }
}
