<?php

require __DIR__ . '/../../vendor/autoload.php';
$app = require __DIR__ . '/../../bootstrap/app.php';
$app->make('Illuminate\\Contracts\\Console\\Kernel')->bootstrap();

use App\Models\Product;
use App\Models\Order;
use App\Models\OrderItem;

$product = Product::find(107);
$order = Order::with('items')->find(86);

$output = [
    'product' => $product ? $product->only(['id','name','tax_id','tax_rate_snapshot','price']) : null,
    'order' => $order ? [
        'id' => $order->id,
        'source' => $order->source,
        'tax_total' => $order->tax_total,
        'subtotal' => $order->subtotal,
        'discount_total' => $order->discount_total,
        'shipping_total' => $order->shipping_total,
        'total_payable' => $order->total_payable,
        'items' => $order->items->map(function ($item) {
            return $item->only(['id','product_id','qty','price','line_total','tax_amount']);
        }),
    ] : null,
];

echo json_encode($output, JSON_PRETTY_PRINT);
