<?php

namespace Modules\HR\Console;

use Illuminate\Console\Command;
use Modules\HR\Services\CrossChex\CrossChexSyncService;

class CrossChexSyncCommand extends Command
{
    protected $signature = 'hr:crosschex-sync';

    protected $description = 'Sync attendance logs from CrossChex Cloud';

    public function handle(
        CrossChexSyncService $service
    ): int {
        try {

            $result = $service->sync();

            $this->info('CrossChex Sync Completed');

            $this->table(
                ['Metric', 'Count'],
                [
                    ['Inserted', $result['inserted']],
                    ['Skipped', $result['skipped']],
                ]
            );

            return self::SUCCESS;

        } catch (\Throwable $e) {

            $this->error($e->getMessage());

            return self::FAILURE;
        }
    }
}
