<?php

namespace Modules\Internal\Transformers;

use Illuminate\Http\Resources\Json\JsonResource;

class ClaimRequestResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        $filesGroupByType = $this->files->mapToGroups(function($file) {
            return [$file->type => $file];
        });

        $data = [
            'id' => $this->id,
            'code' => $this->code,
            'submission_date' => $this->submission_date,
            'member' => $this->member,
            'status' => $this->status ?? 'unknown',
            'service_name' => $this->service->name,
            'payment_type' => $this->payment_type,
            'payment_type_name' => $this->payment_type_name,
            'files_by_type' => $filesGroupByType
        ];

        return $data;
    }
}
