<?php

namespace App\Http\Resources\Streamer;

use App\Http\Resources\BaseResource;
use Illuminate\Http\Request;

final class StreamerResource extends BaseResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->whenHas('id'),
            'code' => $this->code,
            'name' => $this->user->name ?? 'Unknown',
            'truename' => $this->user->truename ?? null,
            'photo_url' => $this->when($this->user->photo ?? false, fn () => asset($this->user->photo)),
            'percentage' => (float) $this->percentage,
        ];
    }
}
