<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;use Illuminate\Http\Resources\Json\JsonResource;
class TransferResource extends JsonResource {public function toArray(Request $r):array{return ['id'=>$this->id,'reference'=>$this->reference,'status'=>$this->status->value,'corridor_id'=>$this->corridor_id,'sender'=>['name'=>$this->sender_name,'phone'=>$this->sender_phone,'id_type'=>$this->sender_id_type,'id_number'=>$r->user()?->hasRole('admin')?$this->sender_id_number:substr($this->sender_id_number,0,2).'***'],'recipient'=>['name'=>$this->recipient_name,'phone'=>$this->recipient_phone,'country_id'=>$this->recipient_country_id,'city'=>$this->recipient_city],'send_amount'=>new MoneyResource($this->send_amount_minor,$this->send_currency),'fee'=>new MoneyResource($this->fee_minor,$this->send_currency),'total_collected'=>new MoneyResource($this->total_collected_minor,$this->send_currency),'payout_amount'=>new MoneyResource($this->payout_amount_minor,$this->receive_currency),'rate_used'=>(string)$this->rate_used,'issued_at'=>$this->issued_at?->toISOString(),'expires_at'=>$this->expires_at?->toISOString(),'redeemed_at'=>$this->redeemed_at?->toISOString(),'events'=>$this->whenLoaded('events',fn()=> $this->events->map(fn($e)=>['event'=>$e->event,'meta'=>$e->meta,'actor_user_id'=>$e->actor_user_id,'created_at'=>$e->created_at->toISOString()]))];}}
