<?php

namespace App\Http\Resources;


use Illuminate\Http\Resources\Json\JsonResource;

class UserRewardResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        $emailReminder = null;
        if ($request->has('isAdmin')) {
            $keyValuePairs = $this->user->attributesKVP()->get();
            $emailReminder = KeyValueBasicResource::collection($keyValuePairs);
            $this->voucher->email = $emailReminder;
        }

        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'reward' => new RewardResource($this->reward),
            'voucher' => new VoucherResource($this->voucher),
            'created_at' => $this->created_at
        ];
    }
}
