<?php

namespace App\Http\Resources;

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

class BankStatementDetailResource extends JsonResource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $transaction = $this->transaction;
        $accountStatement = $transaction->statement;
        return [
            'id' => $this->id,
            'date' => Carbon::parse($transaction->posting_date)->format('Y-m-d'),
            'transaction_description_1' => $transaction->transaction_description,
            'transaction_description_2' => $transaction->transaction_description_2,
            'transaction_description_3' => $transaction->transaction_description_3,
            'transaction_description_4' => $transaction->transaction_description_4,
            'transaction_description_5' => $transaction->transaction_description_5,
            'pay_for' => $transaction->transaction_description_2,
            'system_references' => $this->system,
            'amount' => $transaction->amount,
            'account_statement_date_from' => Carbon::parse($accountStatement->date_from)->format('Y-m-d'),
            'account_statement_date_to' => Carbon::parse($accountStatement->date_to)->format('Y-m-d'),
        ];
    }
}
