<?php

namespace App\Http\Resources;

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

class OrderItemResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'garment_name' => $this->garmentType?->name,
            // explicit, non-colliding keys:
            'age_type_label' => $this->ageType?->name ?? $this->age_type ?? '—',
            'qty' => $this->qty,
            'unit_price' => $this->unit_price,
            'addon_total' => $this->addon_total,
            'total_amount' => $this->total_amount,
            'notes' => $this->notes,
            'addons' => $this->addons->map(fn ($a) => [
                'id' => $a->id,
                'name' => $a->name,
                'price' => $a->pivot->price,
            ]),
        ];
    }
}
