<?php

namespace Modules\Internal\Services;

use App\Exceptions\ImportRowException;
use App\Models\Benefit;
use App\Models\Corporate;
use App\Models\Icd;
use App\Models\Plan;
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;

class IcdService
{
    protected function validateDiagnosisExclusionRow($row)
    {
        if (empty($row['ICD_Code'])) {
            throw new ImportRowException(__('ICD_Code is REQUIRED'), 0, null, $row);
        }
    }

    public function handleIcdRow($row, $id)
    {
        try {
            $this->validateDiagnosisExclusionRow($row);
            $icd = Icd::updateOrCreate([
                'code' => $row['ICD_Code']
            ], [
                "code" => $row['ICD_Code'],
                "parent_code" => null,
                "rev" => '',
                "name" => $row['Description'] ?? null,
                "version" => null,
                "active" => 1,
                "icd_template_id" => $id,
            ]);

            return true;
        } catch (\Exception $e) {
            throw $e;
        }
    }

    public $listing_doc_headers = [
    //    "Rev",
    //    "Version",
       "Code",
    //    "Parent Code",
    //    "Name",
       "Description",
    //    "Status",
    //    "Type"
    ];
}
