<?php

namespace App\Http\Resources;

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

class OrderResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'customer_id' => $this->customer_id,
            'customer_name' => $this->customer?->name ?? 'Unknown',
            'stage' => $this->stage,
            'total_amount' => $this->total_amount,
            'discount' => $this->discount,
            'extra_amount' => $this->extra_amount,
            'extra_amount_reason' => $this->extra_amount_reason,
            'advance_amount' => $this->advance_amount,
            'balance_amount' => $this->balance_amount,
            'delivery_date' => $this->delivery_date,
            'notes' => $this->notes,
            'created_at' => $this->created_at,
            'items' => OrderItemResource::collection($this->whenLoaded('items')),
        ];
    }
}
