<?php
namespace NGauge\Magento\console;

use yii\console\Controller;
use NGauge\Magento\services\MagentoClient;

class ImportMagentoOrdersController extends Controller
{
    public $baseUrl;
    public $accessToken;

    public function options($actionID)
    {
        return ['baseUrl', 'accessToken'];
    }

    public function actionRun()
    {
        if (empty($this->baseUrl) || empty($this->accessToken)) {
            $this->stderr("Please provide --baseUrl and --accessToken\n");
            return 1;
        }

        $client = new MagentoClient($this->baseUrl, $this->accessToken);

        $this->stdout("Fetching orders from {$this->baseUrl}...\n");
        $orders = $client->getOrders(['searchCriteria[pageSize]' => 20]);

        $this->stdout("Got orders: " . json_encode(array_keys($orders)) . "\n");

        // TODO: map and import orders into NGauge data model.
        $this->stdout("Import stub finished. Implement mapping to your app.\n");
        return 0;
    }
}
