<?php

namespace App\Actions\BulkExport;

use App\Models\Order;
use App\Services\BulkExport\ProcessExport;

class ExportFileAction
{
    protected ProcessExport $bulkExport;

    protected $fileName;

    protected string $directory = '';

    /**
     * @param $fileName
     * @param $action
     */
    public function __construct($fileName, $action)
    {
        $this->fileName = $fileName;
       if ($action === 'order') {
            $this->directory = 'exports/orders';
        }
        $this->bulkExport = new ProcessExport($this->directory, $fileName, Order::class);
    }

    /**
     * Download the exported file from directory
     */
    public function download()
    {
        return $this->bulkExport->downloadFile($this->fileName);
    }

    /**
     * Delete the exported file from directory
     */
    public function delete()
    {
        $this->bulkExport->deleteFile($this->fileName);
    }
}
