<?php

namespace App\Http\Resources;

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

class GroupResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'original_amount' => (double) $this->original_amount,
            'original_currency' => new CurrencyResource($this->original_currency),
            'amount' => (double) $this->amount,
            'currency' => new CurrencyResource($this->currency),
            'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'),
            'currency_rate' => (float) $this->currency_rate,
            'transactions' => TransactionResource::collection($this->transactions()->get()),
        ];
    }
}
