<?php

namespace App\Http\Resources\Order;

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

class OrderSyncResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'order' => [
                'uuid' => $this->uuid,
                'order_number' => $this->order_number,
                'outlet_id' => $this->outlet_id,
                'outlet_name_snapshot' => $this->outlet_name_snapshot,
                'outlet_phone_number_snapshot' => $this->outlet_phone_number_snapshot,
                'outlet_address_snapshot' => $this->outlet_address_snapshot,
                'customer_id' => $this->customer_id,
                'customer_name_snapshot' => $this->customer_name_snapshot,
                'customer_email_snapshot' => $this->customer_email_snapshot,
                'customer_phone_number_snapshot' => $this->customer_phone_number_snapshot,
                'customer_address_snapshot' => $this->customer_address_snapshot,
                'source' => $this->source,
                'already_read' => $this->already_read,
                'order_status' => $this->order_status,
                'delivery_type' => $this->delivery_type,
                'delivery_preference' => $this->delivery_preference,
                'delivery_fee_type' => $this->delivery_fee_type,
                'delivery_fee' => (float) $this->delivery_fee,
                'total_delivery_fee' => (float) $this->total_delivery_fee,
                'total_order' => (float) $this->total_order,
                'total_amount' => (float) $this->total_amount,
                'notes' => $this->notes,
                'payment_proof_url' => $this->payment_proof_url,
                'payment_method' => $this->payment_method,
                'created_at' => $this->created_at->toDateTimeString(),
                'updated_at' => $this->updated_at->toDateTimeString(),
            ],
            'items' => $this->whenLoaded('items'),
            'customer' => $this->whenLoaded('customer'),
        ];
    }
}
