<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class UserCommitteesResourceList extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */

    public function toArray($request)
    {
        $member = $this->member;

        $out = [
            'id'                => $this->id,
            'name'              => $this->name,
            'lastName'          => $this->last_name,
            'email'             => $this->email,
            'function'          => $this->function,
            'phoneNumber'       => $this->phone_number,
            'imageLinks'        => getProfileImage($this->image, ['100x100']),
            'profileStatus'     => $this->profile_status,
            'state'             => $this->state,
        ];

        if (!empty($member)) {
            $out['member'] = new MemberResource($member);
        }

        if (!empty($this->committees)) {
            $out['userCommittees'] = CommitteeWithWorkGroupsListResource::collection($this->committees);
        }

        if (!empty($this->workGroups)) {
            $out['userWorkgroups'] = WorkGroupListResource::collection($this->workGroups);
        }

        return $out;
    }
}
