<?php

namespace Modules\Accounts\Transformers;

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

class BankAccountResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'account_id' => $this->account_id,
            'project_id' => $this->project_id,
            'bank_name' => $this->bank_name,
            'account_number' => $this->account_number,
            'branch_name' => $this->branch_name,
            'routing_no' => $this->routing_no,
            'currency' => $this->currency,
            'balance' => $this->balance,
            'account' => $this->whenLoaded('account', fn () => [
                'id' => $this->account?->id,
                'account_code' => $this->account?->account_code,
                'account_name' => $this->account?->account_name,
            ]),
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
