<?php

namespace App\Http\Controllers;

use App\Exports\StandardEquipmentExport;
use App\Imports\StandardEquipmentImport;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Excel as ExcelFormat;
use Maatwebsite\Excel\Facades\Excel;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

class StandardEquipmentManagementController extends Controller
{
    public function export(): BinaryFileResponse
    {
        return Excel::download(
            new StandardEquipmentExport(),
            'standard_equipment.csv',
            ExcelFormat::CSV,
            ['Content-Type' => 'text/csv']
        );
    }

    public function import(Request $request): array
    {
        $request->validate(['file' => 'required|file|mimes:csv,txt']);

        Excel::import(new StandardEquipmentImport(), $request->file('file'));

        return ['success' => true];
    }
}
