<?php

namespace App\Imports\Docter;

use App\Models\Docter;
use App\Models\DocterOrganization;
use App\Models\Organization;
use App\Models\Qualification;
use Maatwebsite\Excel\Concerns\ToModel;

class DocterOrganizationInfo implements ToModel
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        if (($row[0] == "姓名")) {
            return null;
        }
        $docter_id = null;
        if ($row[0]){
            $docter_id = Docter::firstOrCreate([
                'name' => $row[0],
            ]);
        }
        $org_id = null;
        if ($row[6]){
            $org_id = Organization::firstOrCreate([
               'name' => $row[6],
            ]);
        }

        $qualification_id = null;
        if ($row[2])
        {
            $qualification_id = Qualification::firstOrCreate([
                'name' => $row[2]
            ],[
                'name' => $row[2],
                'status' =>1
            ]);
        }
        return new DocterOrganization([
            //
            'docter_id' => $docter_id['id'],
            'organization_id' => $org_id['id'],
            'qualifications_id' =>$qualification_id['id'],
            'state' => 1
        ]);
    }
}
