<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class MemberDataTableResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $data = parent::toArray($request);
        $data['claim_grouped_by_status'] = $this->claims->groupBy('status');
        $data['total_claims'] = [
            'draft'         => count($data['claim_grouped_by_status']['draft'] ?? []),
            'requested'     => count($data['claim_grouped_by_status']['requested'] ?? []),
            'received'      => count($data['claim_grouped_by_status']['received'] ?? []),
            'approved'      => count($data['claim_grouped_by_status']['approved'] ?? []),
            'paid'          => count($data['claim_grouped_by_status']['paid'] ?? []),
            'declined'      => count($data['claim_grouped_by_status']['declined'] ?? [])
        ];

        // $data = ['fuck' => 'you'];

        return $data;
    }
}
