<?php

namespace App\Http\Resources\Order;

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

class OrderInfoResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->uuid,
            'order_number' => $this->order_number,
            'created_at' => $this->created_at->toDateTimeString(),
            'order_status' => $this->order_status,
            'is_cancellation' => $this->is_cancellation,
            'cancellation_accepted' => $this->cancellation_accepted,
            'approval_process' => $this->approval_process,
            'delivery_type' => $this->delivery_type,
            'delivery_preference' => $this->delivery_preference,
            'outlet_name_snapshot' => $this->outlet_name_snapshot,
            'outlet_address_snapshot' => $this->outlet_address_snapshot,
            'customer_address_snapshot' => $this->customer_address_snapshot,
            'order_items' => OrderItemInfoResource::collection($this->whenLoaded('items')),
            'payment_method' => $this->payment_method,
            'payment_proof_url' => $this->payment_proof_url,
            'total_order' => (float) $this->total_order,
            'delivery_fee_type' => $this->delivery_fee_type,
            'delivery_fee' => (float) $this->delivery_fee,
            'total_delivery_fee' => (float) $this->total_delivery_fee,
            'total_amount' => (float) $this->total_amount
        ];
    }
}
