<?php

namespace Modules\Client\Transformers\Dashboard;

use Illuminate\Http\Resources\Json\JsonResource;

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

        return [
            'companyName' => $this->name,
            'policyNumber' => $this->currentPolicy->code,
            'totalMembers' => $this->employees_count,
            'totalCases' => $this->claims_count,
            'myLimit' => [
                'balance' => $myLimitBalance,
                'total' => $myLimitTotal,
                'percentage' => $myLimitTotal ? round(($myLimitBalance / $myLimitTotal) * 100, 2) : 0,
            ],
            'maxTopUp' => ($myLimitTotal - $myLimitBalance)
        ];
    }
}
