<?php

namespace Modules\Vrc\Http\Controllers\Registers;

use Modules\Vrc\Entities\VrcTechnician;
use Modules\Vrc\Entities\VrcTechnicianCertification;

class TechnicianCertificationController extends AbstractRegisterController
{
    protected function schema(): array
    {
        $techs = VrcTechnician::where('business_id', $this->businessId())->pluck('name', 'id')->toArray();
        $status = ['valid' => 'Valid', 'expiring' => 'Expiring', 'expired' => 'Expired'];

        return [
            'key' => 'tech_certs',
            'route' => 'vrc.technician-certifications',
            'model' => VrcTechnicianCertification::class,
            'permView' => 'vrc.technician.view',
            'permManage' => 'vrc.technician.manage',
            'title' => 'Technician Certifications',
            'singular' => 'Certification',
            'columns' => [
                ['key' => 'technician_id', 'label' => 'Technician', 'map' => $techs],
                ['key' => 'name', 'label' => 'Certification'],
                ['key' => 'cert_no', 'label' => 'No.'],
                ['key' => 'expires_on', 'label' => 'Expires', 'type' => 'date'],
                ['key' => 'status', 'label' => 'Status', 'map' => $status, 'badge' => ['valid' => 'success', 'expiring' => 'warning', 'expired' => 'danger']],
            ],
            'fields' => [
                ['name' => 'technician_id', 'label' => 'Technician', 'type' => 'select', 'options' => $techs, 'required' => true, 'col' => 6],
                ['name' => 'name', 'label' => 'Certification name', 'type' => 'text', 'required' => true, 'col' => 6, 'max' => 191],
                ['name' => 'cert_no', 'label' => 'Certificate no.', 'type' => 'text', 'col' => 4, 'max' => 120],
                ['name' => 'issuer', 'label' => 'Issuer', 'type' => 'text', 'col' => 8, 'max' => 191],
                ['name' => 'issued_on', 'label' => 'Issued on', 'type' => 'date', 'col' => 4],
                ['name' => 'expires_on', 'label' => 'Expires on', 'type' => 'date', 'col' => 4],
                ['name' => 'status', 'label' => 'Status', 'type' => 'select', 'options' => $status, 'col' => 4, 'default' => 'valid'],
                ['name' => 'notes', 'label' => 'Notes', 'type' => 'textarea', 'col' => 12],
            ],
        ];
    }
}
