<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use App\Models\{{modelName}};

class {{modelName}}Resource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
            // Add your fields here

            // Conditional fields
            // $this->mergeWhen($request->user()?->isAdmin(), [
            //     'internal_notes' => $this->internal_notes,
            // ]),

            // Relationships
            // 'user' => new UserResource($this->whenLoaded('user')),
        ];
    }

    /**
     * @param \Illuminate\Database\Eloquent\Collection<{{modelName}}> $resource
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<{{modelName}}Resource>
     */
    public static function collection($resource): AnonymousResourceCollection
    {
        return parent::collection($resource);
    }
}
