<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class User extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $datose = json_decode($this->datosE);
        //$datose = json_decode($this->UserView->datosE);
        return [
            'idE'           => strval($this->idE),
            'idU'           => strval($this->idU),
            'username'      => $this->username,
            'name'          => isset($datose->name->value)?$datose->name->value:'',
            'email'         => $this->email,
            'token'         => $this->token,
            'permissions'   => Permissions::collection($this->getAllPermissions()),
            'roles'         => $this->getRoleNames(),
        ];

    }
}
