<?php

namespace App\Console\Commands;

use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;

#[Signature('badhonsworld:sync-stock')]
#[Description('Synchronize stock levels for all products imported from badhonsworld.com')]
class BadhonsworldSyncCommand extends Command
{
    /**
     * Execute the console command.
     */
    public function handle(\App\Services\BadhonsworldService $service)
    {
        $this->info('Starting stock synchronization with badhonsworld.com...');
        
        try {
            $syncedCount = $service->syncAllProductStock();
            $this->info("Stock synchronization completed successfully! Synced/updated stock for {$syncedCount} products.");
        } catch (\Exception $e) {
            $this->error('An error occurred during synchronization: ' . $e->getMessage());
            return Command::FAILURE;
        }

        return Command::SUCCESS;
    }
}
