<?php

namespace Modules\Client\Transformers\AlarmCenter;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\Service;

class DataListClaimMemberResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        $serviceData = Service::where('code', $this->service_code)->first();
        if ($serviceData) {
            $serviceName = $serviceData->name;
        } else {
            $serviceName = $this->service_cod;
        }

        if ($this->status == 'approved' && $this->status_final_log ){
            $status = 'Done';
        } else if ($this->status == 'declined' || $this->status_final_log == 'declined') {
            $status = 'Declined';
        } else {
            $status = 'Ongoing';
        }
        return [
            'id' => $this->id,
            'admission_date' => $this->submission_date ?? null,
            'discharge_date' => $this->discharge_date ?? null,
            'code' => $this->code ?? null,
            'service_type' => $serviceName,
            'status' => $status,
        ];
    }
}
