<?php

namespace App\Imports;

use App\Models\Beneficiary;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class BeneficiaryImport implements ToModel, WithHeadingRow
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new Beneficiary([
            'name'               => $row['nama'] ?? $row['name'],
            'nik'                => $row['nik'],
            'address'            => $row['alamat'] ?? $row['address'],
            'village'            => $row['desa'] ?? $row['village'],
            'district'           => $row['kecamatan'] ?? $row['district'],
            'foster_parent_name' => $row['nama_orang_tua_asuh'] ?? $row['foster_parent_name'],
            'foster_parent_role' => $row['jabatan_orang_tua_asuh'] ?? $row['foster_parent_role'],
            'latitude'           => $row['latitude'] ?? null,
            'longitude'          => $row['longitude'] ?? null,
            'status'             => 'active',
        ]);
    }
}
