<?php

namespace App\Console\Commands;

use App\Models\Order;
use App\Shopify\ShopifyService;
use Illuminate\Console\Command;

class GetFulfillmentOrders extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'area:get-fulfillment-orders {order_number}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Gets an order fulfillment orders';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(ShopifyService $service)
    {
        $number = $this->argument('order_number');
        if (!$number) {
            $this->error('You have to specify the order number');
            return 0;
        }
        $order = Order::where('order_number', $number)->first();
        if (!$order) {
            $this->error('Order not found!');
            return 0;
        }
        // echo json_encode($service->getFulfillmentOrders($order));
        echo json_encode($service->getOpenFulfillmentOrderId($order));
        return 0;
    }
}
