<?php

namespace App\Classes\Modules\Transactions\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Processors\ETLPDFPurchaseOrderClaudeProcessor;
use App\Classes\Modules\Transactions\Standards\Rules\CanETLPurchaseOrder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class ETLPurchaseOrderTransactionLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification(): array
    {
        return [
            'title' => 'ETL Purchase Order',
            'message' => 'You have successfully etl purchase order document'
        ];
    }

    /** @var CanETLPurchaseOrder */
    private $canETLPurchaseOrder;

    /** @var ETLPDFPurchaseOrderClaudeProcessor */
    private $eTLPDFPurchaseOrderClaudeProcessor;

    /**
     * ETLPurchaseOrderTransactionLogic constructor.
     * @param CanETLPurchaseOrder $canETLPurchaseOrder
     * @param ETLPDFPurchaseOrderClaudeProcessor $eTLPDFPurchaseOrderClaudeProcessor
     */
    public function __construct(CanETLPurchaseOrder $canETLPurchaseOrder, ETLPDFPurchaseOrderClaudeProcessor $eTLPDFPurchaseOrderClaudeProcessor)
    {
        $this->canETLPurchaseOrder = $canETLPurchaseOrder;
        $this->eTLPDFPurchaseOrderClaudeProcessor = $eTLPDFPurchaseOrderClaudeProcessor;
    }

    /**
     * @param Request $request
     * @param string $id
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\InternalServerErrorException
     */
    public function logic(Request $request, $id = ''): JsonResponse
    {
        $this->canETLPurchaseOrder->passes();

        // if ($request->has('products') && is_array($request->input('products'))) {
        //     $products = $request->input('products');
        //     $productsMetadata = $request->input('productsMetadata');
        // }

        // try{
        //     $products = $this->etlPDFPurchaseOrderTransactionProcessor->execute($products, $productsMetadata);
        // } catch (\Exception $exception) {
            // Log::info('Exception: ' .json_encode($exception));
        //     throw new InternalServerErrorException('Something went wrong!');
        // }

        $files = $request->input('files');
        $result = $this->eTLPDFPurchaseOrderClaudeProcessor->execute($files);
        return $this->response($result);
    }
}
