<?php

namespace App\Http\Resources;

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

class TransactionResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'id' => $this->id,
            'booking' => new BookingResource($this->booking),
            'type' => (int) $this->type,
            'bill_no' => $this->bill_no,
            'amount' => (double) $this->amount,
            'original_amount' => (double) $this->original_amount,
            'currency' => new CurrencyResource($this->currency),
            'original_currency' => new CurrencyResource($this->original_currency),
            'currency_rate' => (double) $this->currency_rate,
            'status' => (int) $this->status,
            'details' => TransactionDetailResource::collection($this->transactionDetails),
            'documents' => new DocumentResource($this->documents()->first()),
            'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:s:i'),
            'updated_at' => Carbon::parse($this->update_at)->format('d-m-Y h:s:i')
        ];
    }
}
