<?php

namespace Modules\Inventory\Services;

use Illuminate\Support\Facades\DB;
use Modules\Inventory\Models\PurchaseInvoice;

class PurchaseInvoicePostingService
{
    /* public function __construct(
        protected InventoryPostingService $inventoryPostingService,
        protected PurchaseAccountingPostingService $accountingPostingService,
        protected PurchaseRepository $purchaseRepository,
        protected PurchaseRequisitionRepository $purchaseReqRepository,
    ) {} */

    public function post(PurchaseInvoice $invoice): void
    {
        if ($invoice->is_posted) {
            return;
        }

        DB::transaction(function () use ($invoice) {

            /*
             |--------------------------------------------------------------------------
             | Inventory Posting
             |--------------------------------------------------------------------------
             */

            /* $this->inventoryPostingService->post($invoice); */

            /*
             |--------------------------------------------------------------------------
             | Accounting Posting
             |--------------------------------------------------------------------------
             */

            /* $voucher = $this->accountingPostingService->post($invoice); */

            /*
             |--------------------------------------------------------------------------
             | Mark Invoice Posted
             |--------------------------------------------------------------------------
             */

            /* $invoice->update([

                'status' => PurchaseStatusEnum::POSTED,

                'voucher_id' => $voucher->id,

                'approved_at' => now(),

                'approved_by' => auth()->id(),

                'is_posted' => true,

            ]); */

            /*
             |--------------------------------------------------------------------------
             | Close Purchase Requisition
             |--------------------------------------------------------------------------
             */

            /* $invoice->purchaseRequisition?->update([

                'status' => PurchaseRequisitionStatusEnum::CLOSED,

                'closed_at' => now(),

            ]); */

        });
    }
}
