<?php

namespace Modules\Accounts\Transformers;

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

class VoucherResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'voucher_no' => $this->voucher_no,
            'voucher_date' => $this->voucher_date?->toDateString(),
            'voucher_type' => $this->voucher_type,
            'project_id' => $this->project_id,
            'reference' => $this->reference,
            'status' => $this->status,
            'reversed_from' => $this->reversed_from,
            'is_reversal' => $this->is_reversal,
            'posted_by' => $this->posted_by,
            'posted_at' => $this->posted_at,
            'created_by' => $this->created_by,
            'lines' => VoucherLineResource::collection($this->whenLoaded('lines')),
            'transactions' => TransactionResource::collection($this->whenLoaded('transactions')),
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
