<?php

namespace App\Console\Commands\Pimcore;

use App\Facades\PimcoreCustomerImportService;
use Illuminate\Console\Command;

class ImportUsers extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'pimcore:import-users {pimcoreAdminSid} {fromId} {toId?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Import users from Pimcore along with their accounts and profiles if they exist';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $fromId = $this->argument('fromId');
        $toId = $this->argument('toId') ?? $fromId;
        $pimcoreAdminSid = $this->argument('pimcoreAdminSid');

        if ($fromId === 'all') {
            PimcoreCustomerImportService::importAllCustomers($pimcoreAdminSid);
            return 0;
        }
        PimcoreCustomerImportService::importCustomers($fromId, $toId, $pimcoreAdminSid);
        return 0;
    }
}
