<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

class RatingResource extends JsonResource
{
  public function toArray(Request $request): array
  {
    return [
      'id' => $this->id,
      'user_id' => $this->user_id,
      'rateable_type' => class_basename($this->rateable_type),
      'rateable_id' => $this->rateable_id,
      'score' => (int) $this->score,
      'rate' => (int) $this->score,
      'comment' => $this->comment,
      'created_at' => $this->created_at?->toISOString(),
      'updated_at' => $this->updated_at?->toISOString(),
      'user' => new UserResource($this->whenLoaded('user')),
    ];
  }
}
