<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class SumTotalClientPaymentResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
         return [
            'client_name'      => $this->client ? $this->client->name : '',
            'co_name'          => $this->co ? $this->co->name : '',
            'loan_code'        => $this->loan ? $this->loan->loan_code : '',
            'received_date'   => $this->received_date ?? '',
            'paid_principal'  => $this->paid_principal ?? 0,
            'paid_interest'   => $this->paid_interest ?? 0,
            'paid_penalty'    => $this->paid_penalty ?? 0,
            'received_date'    => $this->received_date ?? 0,
            'total_collected' => ($this->paid_principal ?? 0)
                               + ($this->paid_interest ?? 0)
                               + ($this->paid_penalty ?? 0),
        ];
    }
} 
