<?php

namespace App\Console\Commands;

use App\Exports\AcademyMemberDependentsSampleExport;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel;

class GenerateAcademySampleImportCommand extends Command
{
    protected $signature = 'academy:sample-import 
        {--path= : Path inside storage/app (default: samples/academy_member_dependents_sample.xlsx)}';

    protected $description = 'Generate sample Excel (12 members: 10 with 3–5 deps, 1 member-only, 1 incomplete row) for academy import';

    public function handle(): int
    {
        $relative = $this->option('path') ?: 'samples/academy_member_dependents_sample.xlsx';
        $dir = trim((string) dirname($relative), '.');
        if ($dir !== '' && $dir !== DIRECTORY_SEPARATOR) {
            Storage::disk('local')->makeDirectory($dir);
        }

        Excel::store(new AcademyMemberDependentsSampleExport(), $relative, 'local');

        $this->info('Written: ' . storage_path('app/' . $relative));

        return self::SUCCESS;
    }
}
