<?php

namespace Modules\Client\Transformers\Dashboard;

use Illuminate\Http\Resources\Json\JsonResource;

class LimitResources extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $myLimitBalance = (int)$this->currentPolicy->limit_balance;
        $myLimitTotal = (int)$this->currentPolicy->total_premi;

        $lockBalance = (int)$this->currentPolicy->minimal_stop_service_net;
        $lockPercentage = (int)$this->currentPolicy->minimal_stop_service_percentage;

        return [
            'myLimit' => [
                'balance' => $myLimitBalance,
                'total' => $myLimitTotal,
                'percentage' => $myLimitTotal ? round(($myLimitBalance / $myLimitTotal) * 100, 2) : 0,
            ],
            'lockLimit' => [
                'balance' => $lockBalance,
                'percentage' => $lockPercentage
            ]
        ];
    }
}
