<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;use Illuminate\Http\Resources\Json\JsonResource;
class MerchantResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'=>$this->id,'code'=>$this->code,'name'=>$this->name,'status'=>$this->status->value,
            'country'=>$this->whenLoaded('country',fn()=>['id'=>$this->country->id,'iso2'=>$this->country->iso2,'iso3'=>$this->country->iso3,'name'=>$this->country->name,'dial_code'=>$this->country->dial_code,'currency_code'=>$this->country->currency_code]),
            'currency_code'=>$this->currency_code,'contact_name'=>$this->contact_name,'contact_phone'=>$this->contact_phone,'contact_email'=>$this->contact_email,'address'=>$this->address,
            'can_send'=>$this->can_send,'can_receive'=>$this->can_receive,
            'per_txn_min'=>new MoneyResource($this->per_txn_min_minor,$this->currency_code),
            'per_txn_max'=>new MoneyResource($this->per_txn_max_minor,$this->currency_code),
            'daily_limit'=>new MoneyResource($this->daily_limit_minor,$this->currency_code),
            'float_balance'=>new MoneyResource($this->float_balance_minor,$this->currency_code),
            'created_at'=>$this->created_at?->toISOString(),'updated_at'=>$this->updated_at?->toISOString(),
        ];
    }
}
