<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class TeamResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'         => $this->id,
            'name'       => $this->name,
            'short'      => $this->short,
            'letter'     => $this->letter,
            'color'      => $this->color,
            'city'       => $this->city,
            'founded'    => $this->founded,
            'coach'      => $this->coach,
            'stadium'    => $this->stadium,
            'logoUrl'    => $this->logo_url,
            'isHomeTeam' => (bool) $this->is_home_team,
            'players'    => PlayerResource::collection($this->whenLoaded('players')),
        ];
    }
}
