<?php

namespace App\Http\Controllers\Api\V1\Favorite\Resources;

use App\Http\Controllers\Api\V1\Product\Resources\ProductResource;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class FavoriteResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  Request  $request
     * @return array|Arrayable|\JsonSerializable
     */
    public function toArray($request): array
    {
        return [
            'created_at' => $this->created_at,
            'product' => new ProductResource($this->whenLoaded('product')),
        ];
    }
}
