<?php

namespace Modules\Inventory\Transformers\Purchase;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Accounts\Transformers\CoaResource;

class PurchasePaymentIndexResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'payment_date' => $this->payment_date,
            'amount' => $this->amount,
            'payment_method' => $this->payment_method,
            'reference' => $this->reference,
            'account' => new CoaResource($this->whenLoaded('account')),
            'voucher' => $this->whenLoaded('voucher', function () {
                return $this->voucher;
            }),
            'status' => $this->status,
            'is_posted' => $this->is_posted,
            'posted_at' => $this->posted_at,
            'can_be_posted' => $this->isEligibleForPosting(),
        ];
    }
}
