<?php

namespace Modules\User\Transformers;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;

class UserListResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'ic_number' => $this->ic_number,
            'position' => $this->position,
            'phone_number' => $this->phone_number,
            'image_url' => $this->image_url ? Storage::disk('public')->url($this->image_url) : null,
            'status' => $this->status,
            'email_verified_at' => $this->email_verified_at,
            'gender' => $this->gender,
            'marriage_status' => $this->marriage_status,
            'member_number' => $this->member_number,
            'member_type' => $this->member_type,
            'join_date' => $this->join_date,
            'birth_date' => $this->birth_date,
            'birth_place' => $this->birth_place,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'deleted_at' => $this->deleted_at,
            'roles' => $this->roles->map(function ($role) {
                return [
                    'id' => $role->id,
                    'name' => $role->name,
                    'guard_name' => $role->guard_name,
                ];
            }),
        ];
    }
}
