<?php

namespace App\Console\Commands;

use App\Imports\LocationSheetImport;
use Illuminate\Console\Command;
use Maatwebsite\Excel\Facades\Excel;

class ImportLocationSheet extends Command
{
    protected $signature = 'import:location {file? : Path to Map location.xlsx}';

    protected $description = 'Import ground team / location sheet (territory, employee, doctors, p-lat, p-long)';

    public function handle(): int
    {
        $file = $this->argument('file') ?? base_path('Map location.xlsx');

        if (! file_exists($file)) {
            $this->error("File not found: {$file}");

            return self::FAILURE;
        }

        $this->info("Importing: {$file}");
        Excel::import(new LocationSheetImport, $file);
        $this->info('Done.');

        return self::SUCCESS;
    }
}
