<?php

namespace App\Http\Resources\OLDLMS;

use App\Services\ClaimService;
use Illuminate\Http\Resources\Json\JsonResource;

class MemberResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        // $data = parent::toArray($request);
        $currentMemberPlan = $this->memberPlans?->first();

        $data = [
            'member_id' => $this->member_id,
            'birth_date' => $this->birth_date,
            'email' => $this->email,
            'phone' => $this->person->phone ?? null,
            'full_name' => $this->full_name,
            'nric' => $this->nric,
            'plan' => $currentMemberPlan ? [
                'code' => $currentMemberPlan->plan->code ?? null,
                'start' => $currentMemberPlan->start,
                'end' => $currentMemberPlan->end,
                'limit' => $this->currentPlan->limit_rules
            ] : null,
            'policy_code' => $this->currentPolicy?->code ?? null,
            'corporate' => [
                'code' => $this->currentPolicy?->corporate->code ?? null,
                'name' => $this->currentPolicy?->corporate->name,
                'welcome_message' => $this->currentPolicy?->corporate->welcome_message,
                'help_text' => $this->currentPolicy?->corporate?->help_text,
                'avatar_url' => $this->currentpolicy?->corporate?->avatar_url
            ],
            'limit_usage' => $this->totalUsage ?? null
        ];
        return $data;
    }
}
