<?php

namespace Modules\Internal\Transformers;

use Illuminate\Http\Resources\Json\JsonResource;

class DiagnosisExclusionResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'code' => $this->exclusionable->code,
            'name' => $this->exclusionable->name,
            'diagnosis_type' => $this->exclusionable->type,
            'service_code' => $this->service_code,
            'type' => $this->type,
            'rules' => $this->rules->mapToGroups(function ($item, $key) {
                return [$item['name'] => $item['values']];
            })
        ];
    }
}
