<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class LoanLossProvisionResource extends JsonResource
{
    function funTypeClient($type_loan_loss_provision,$params){
        if($type_loan_loss_provision==2){
            $type_client = 'ក្រោមស្តង់ដារ (Sub-Standard)';
            $type_late = '7-30ថ្ងៃ';
        }
        else if($type_loan_loss_provision==3){
            $type_client = 'សង្ស័យ(Doubful)';
            $type_late = '>30ថ្ងៃ-60ថ្ងៃ';
        }
        else{
            $type_client = 'បាត់បង់(Loan Loss)';
            $type_late = '>60ថ្ងៃ';
        }
        return $params==1?$type_client:$type_late;
    }
    public function toArray($request)
    {
        return [
            'total_loan_out' => $this->total_loan_out,
            'total_loan_balance' => $this->total_loan_balance,
            'total_amount_late' => $this->total_amount_late,
            'total_amount_loss_provision' => $this->total_amount_loss_provision,
            'loss_provision_date' => $this->loss_provision_date,
            'co_name' => $this->co->name,
            'type_client' => $this->funTypeClient($this->type_loan_loss_provision,1),
            'type_late' => $this->funTypeClient($this->type_loan_loss_provision,2),
        ];
    }
}
