<?php

namespace App\Console\Commands;

use App\Models\Order;
use App\SAP\SAPService;
use Illuminate\Console\Command;

class CreatePendingOrdersSap extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'area:create-pending-orders';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Sends pending orders to SAP';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(SAPService $service)
    {
        $orders = Order::where('to_sync', true)
            ->get();

        foreach ($orders as $order) {
            $service->createSapOrder($order);
        }
        return 0;
    }
}
