<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\StudentsTemplateExport;
use App\Exports\ClassesTemplateExport;
use App\Exports\DestinationsTemplateExport;
use App\Exports\BanksTemplateExport;

class GenerateTemplates extends Command
{
    protected $signature = 'templates:generate';
    protected $description = 'Generate sample Excel template files for imports';

    public function handle()
    {
        $templatesDir = public_path('templates');
        if (!file_exists($templatesDir)) {
            mkdir($templatesDir, 0755, true);
        }

        $this->info('Generating templates...');

        Excel::store(new StudentsTemplateExport(), 'students_template.xlsx', 'public');
        $this->line('Created students_template.xlsx');

        Excel::store(new ClassesTemplateExport(), 'classes_template.xlsx', 'public');
        $this->line('Created classes_template.xlsx');

        Excel::store(new DestinationsTemplateExport(), 'destinations_template.xlsx', 'public');
        $this->line('Created destinations_template.xlsx');

        Excel::store(new BanksTemplateExport(), 'banks_template.xlsx', 'public');
        $this->line('Created banks_template.xlsx');

        $this->info('All templates generated successfully!');
        return 0;
    }
}