<?php
declare(strict_types = 1);

namespace App\Http\Resources\Outpatient\Pending;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class PendingListsResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request = null): array
    {
        $lists = [];
        foreach ($this->resource['response'] as $v) {
            $lists[] = [
                'category' => $v['visitType'],
                'visit_date' => date('Y-m-d', strtotime($v['visitDate'])),
                'diagnosis' => $v['outpatientDiagnosis'],
                'dept_id' => $v['treatmentDepartment'],
                'dept_name' => $v['departmentName'],
                'reg_id' => $v['regId'],
                'prescription_id' => $v['prescriptionId'],
                'total_prescription_amount' => (float) $v['prescriptionAmount'],
                'single_prescription_amount' => (float) $v['singleAmount'],
                'doctor_name' => $v['doctorName'],
                'remark' => $v['remarks'],
                'is_self_pay' => $v['isexpense'],
                'prescription_number' => $v['nrescriptionNumber'],
                'exec_address' => $v['takeMedicine'],
                'visit_no' => $v['visitNumber'],
            ];
        }

        return $lists;
    }
}