<?php

namespace App\Services;

use App\Models\Order;
use Exception;
use Illuminate\Support\Facades\Storage;

class GenerateDocumentsService
{
    /**
     * @param Order $order
     * @param int $userId
     * @return string
     * @throws Exception
     */
    public function generateInstallationPack(Order $order, int $userId): string
    {
        $products_sku = $order->products_sku;
        $articles = [];
        Storage::disk('public')->makeDirectory('orders/' . $order->id . '/installation/Схемы сборки');
        foreach ($products_sku as $sku) {
            if(!in_array($sku->product->article, $articles)) {
                $articles[] = $sku->product->article;
                // find and copy scheme files to installation directory
                // ...
            }

            // generate xlsx order file
            // ...

            // create zip archive
            $fileModel = (new FileService())->createZipArchive('orders/' . $order->id . '/installation', 'Installation-' . $order->id . '.zip', $userId);

            // create link
            return $fileModel->link;


        }
    }
}