<?php
namespace App\Services\Generators;
use Illuminate\Support\Facades\Storage;
use App\Models\Quote;

class Kmz2Generator {
	public static function generate(Quote $quote, bool $force = false): array {
		$path = "quotes/{$quote->id}/kmz2.kmz";
		if(!$force && Storage::exists($path)) return [0, Storage::get($path)];
		$kml = view('mail.KMZ2', ['quote' => $quote]);
		$zip = new \ZipArchive();
		if($zip->open(Storage::path($path), \ZipArchive::CREATE | \ZipArchive::OVERWRITE) === true) {
			$zip->addFromString('doc.kml', $kml->render());
			$zip->close();
			return [1, Storage::get($path)];
			}
		return [0, null];
		}
	}
